home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / winprogs / winsck11 / winsock.txt < prev    next >
Encoding:
Text File  |  1993-01-21  |  317.2 KB  |  7,849 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.                                Windows
  20.                                Sockets
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.                            Windows Sockets
  29.                         An Open Interface for
  30.                       Network Programming under
  31.                          Microsoft  Windows
  32.  
  33.                              Version 1.1
  34.  
  35.                            20 January 1993
  36.  
  37.  
  38.                              Martin Hall
  39.                              Mark Towfiq
  40.                              Geoff Arnold
  41.                            David Treadwell
  42.                             Henry Sanders
  43.  
  44.  
  45.  
  46.  
  47.              Copyright  1992 by Martin Hall, Mark Towfiq
  48.            Geoff Arnold, David Treadwell and Henry Sanders
  49.  
  50.                          All rights reserved.
  51.  
  52.           This document may be  freely redistributed in  any
  53.           form, electronic or otherwise, provided that it is
  54.           distributed in its entirety and that the copyright
  55.           and  this  notice  are  included.    Comments   or
  56.           questions may be submitted via electronic mail  to
  57.           winsock@microdyne.com.   Requests to  be added  to
  58.           the  Windows  Sockets   mailing  list  should   be
  59.           addressed to winsock-request@microdyne.com.   This
  60.           specification, archives of  the mailing list,  and
  61.           other information on Windows Sockets are available
  62.           via anonymous  FTP  from the  host  microdyne.com,
  63.           directory /pub/winsock.  Questions about products
  64.           conforming  to   this  specification   should   be
  65.           addressed to the vendors of the products.
  66.  
  67.           Portions of the Windows Sockets specification  are
  68.           derived from material which is Copyright (c) 1982-
  69.           1986  by  the   Regents  of   the  University   of
  70.           California.    All  rights  are  reserved.     The
  71.           Berkeley Software License Agreement specifies  the
  72.           terms and conditions for redistribution.
  73.  
  74.  
  75.           Revision history:
  76.           1.0 Rev.A June 11, 1992
  77.           1.0 Rev.B June 16, 1992
  78.           1.0 Rev. C     October 12, 1992
  79.           1.1       January, 1993
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.                                   ii
  106.                            Windows Sockets
  107.                              Version 1.1
  108. ACKNOWLEDGMENTS..........................................1
  109. 1.  INTRODUCTION.........................................3
  110.      1.1 What is Windows Sockets?........................3
  111.      1.2 Berkeley Sockets................................3
  112.      1.3 Microsoft Windows and Windows-specific extensions 3
  113.      1.4 The Status of this Specification................4
  114.      1.5 Revision History................................4
  115.           1.5.1 Windows Sockets Version 1.0..............4
  116.           1.5.2 Windows Sockets Version 1.1..............4
  117. 2.  PROGRAMMING WITH SOCKETS.............................6
  118.      2.1 Windows Sockets Stack Installation Checking.....6
  119.      2.2 Sockets.........................................6
  120.           2.2.1 Basic concepts...........................6
  121.           2.2.2 Client-server model......................6
  122.           2.2.3 Out-of-band data.........................7
  123.           2.2.4 Broadcasting.............................7
  124.      2.3 Byte Ordering...................................8
  125.      2.4 Socket Options..................................8
  126.      2.5 Database Files..................................9
  127.      2.6 Deviation from Berkeley Sockets.................9
  128.           2.6.1 socket data type and error values........10
  129.           2.6.2 select() and FD_*........................10
  130.           2.6.3 Error codes - errno, h_errno & WSAGetLastError()
  131.           ...............................................10
  132.           2.6.4 Pointers.................................11
  133.           2.6.5 Renamed functions........................11
  134.                2.6.5.1 close() & closesocket()...........11
  135.                2.6.5.1 ioctl() & ioctlsocket()...........11
  136.           2.6.6 Blocking routines & EINPROGRESS..........11
  137.           2.6.7 Maximum number of sockets supported......11
  138.           2.6.8 Include files............................12
  139.           2.6.9 Return values on API failure.............12
  140.           2.6.10 Raw Sockets.............................12
  141.      2.7 Windows Sockets in Multithreaded Versions of Windows
  142.      ....................................................12
  143. 3.  SOCKET LIBRARY OVERVIEW..............................14
  144.      3.1 Socket Functions................................14
  145.           3.1.1 Blocking/Non blocking & Data Volatility..14
  146.      3.2 Database Functions..............................15
  147.      3.3 Microsoft Windows-specific Extension Functions..16
  148.           3.3.1 Asynchronous select() Mechanism..........17
  149.           3.3.2 Asynchronous Support Routines............17
  150.           3.3.3 Hooking Blocking Methods.................17
  151.           3.3.4 Error Handling...........................18
  152.           3.3.5 Accessing a Windows Sockets DLL from an
  153.           Intermediate DLL...............................18
  154.           3.3.6 Internal use of Messages by Windows Sockets
  155.           Implementations................................18
  156.           3.3.7 Private API Interfaces...................19
  157. 4.  SOCKET LIBRARY REFERENCE.............................20
  158.      4.1 Socket Routines.................................20
  159.           4.1.1 accept().................................21
  160.           4.1.2 bind()...................................23
  161.           4.1.3 closesocket()............................25
  162.           4.1.4 connect()................................27
  163.           4.1.5 getpeername()............................29
  164.           4.1.6 getsockname()............................30
  165.           4.1.7 getsockopt().............................31
  166.           4.1.8 htonl()..................................33
  167.           4.1.9 htons()..................................34
  168.                                  iii
  169.           4.1.10 inet_addr().............................35
  170.           4.1.11 inet_ntoa().............................36
  171.           4.1.12 ioctlsocket()...........................37
  172.           4.1.13 listen()................................39
  173.           4.1.14 ntohl().................................41
  174.           4.1.15 ntohs().................................42
  175.           4.1.16 recv()..................................43
  176.           4.1.17 recvfrom()..............................45
  177.           4.1.18 select()................................48
  178.           4.1.19 send()..................................50
  179.           4.1.20 sendto()................................52
  180.           4.1.21 setsockopt()............................55
  181.           4.1.22 shutdown()..............................58
  182.           4.1.23 socket()................................60
  183.      4.2 Database Routines...............................62
  184.           4.2.1 gethostbyaddr()..........................62
  185.           4.2.2 gethostbyname()..........................64
  186.           4.2.3 gethostname()............................65
  187.           4.2.4 getprotobyname().........................66
  188.           4.2.5 getprotobynumber().......................68
  189.           4.2.6 getservbyname()..........................69
  190.           4.2.7 getservbyport()..........................71
  191.      4.3 Microsoft Windows-specific Extensions...........72
  192.           4.3.1 WSAAsyncGetHostByAddr()..................72
  193.           4.3.2 WSAAsyncGetHostByName()..................75
  194.           4.3.3 WSAAsyncGetProtoByName().................78
  195.           4.3.4 WSAAsyncGetProtoByNumber()...............81
  196.           4.3.5 WSAAsyncGetServByName()..................84
  197.           4.3.6 WSAAsyncGetServByPort()..................87
  198.           4.3.7 WSAAsyncSelect().........................90
  199.           4.3.8 WSACancelAsyncRequest()..................96
  200.           4.3.9 WSACancelBlockingCall()..................98
  201.           4.3.10 WSACleanup()............................100
  202.           4.3.11 WSAGetLastError().......................102
  203.           4.3.12 WSAIsBlocking().........................103
  204.           4.3.13 WSASetBlockingHook()....................104
  205.           4.3.14 WSASetLastError().......................106
  206.           4.3.15 WSAStartup()............................107
  207.           4.3.16 WSAUnhookBlockingHook().................111
  208. Appendix A.  Error Codes and Header Files................112
  209.      A.1 Error Codes.....................................112
  210.      A.2 Header Files....................................114
  211.           A.2.1 Berkeley Header Files....................114
  212.           A.2.2 Windows Sockets Header File - winsock.h..115
  213. Appendix B.  Notes for Windows Sockets Suppliers.........127
  214.      B.1 Introduction....................................127
  215.      B.2 Windows Sockets Components......................127
  216.           B.2.1 Development Components...................127
  217.           B.2.2 Run Time Components......................127
  218.      B.3 Multithreadedness and blocking routines.........127
  219.      B.4 Database Files..................................128
  220.      B.5 FD_ISSET........................................128
  221.      B.6 Error Codes.....................................128
  222.      B.7 DLL Ordinal Numbers.............................128
  223.      B.8 Validation Suite................................129
  224. Appendix C.  For Further Reference.......................131
  225. Appendix D.  Background Information......................131
  226.      D.1 Legal Status of Windows Sockets.................131
  227.      D.2 The Story Behind the Windows Sockets Icon.......131
  228.  
  229.  
  230.  
  231.                                   iv
  232.  
  233.  
  234.  
  235.                                                         Introduction 1
  236.  
  237.  
  238. ACKNOWLEDGMENTS
  239.  
  240. The authors would like to thank their companies for allowing them the
  241. time and resources to make this specification possible:  JSB
  242. Corporation, Microdyne Corporation, FTP Software, Sun Microsystems,
  243. and Microsoft Corporation.
  244.  
  245. Special thanks should also be extended to the other efforts
  246. contributing to the success of Windows Sockets. The original draft was
  247. heavily influenced by existing specifications offered and detailed by
  248. JSB Corporation and Net Manage, Inc. The "version 1.0 debate" hosted
  249. by Microsoft in Seattle allowed many of the members of the working
  250. group to hash out final details for 1.0 vis-a-vis.
  251.  
  252. Sun Microsystems was kind enough to allow first time implementors to
  253. "plug and play" beta software during the first Windows Sock-A-Thon of
  254. Windows Sockets application  and implementation
  255.                            s                     at Interop
  256.                                                s            Fall '92.
  257. Microsoft has shared WSAT (the Windows Sockets API Tester) with other
  258. Windows Sockets implementors as a standard Windows Sockets test suite
  259. to aid in testing their implementations. Finally, Sun Microsystems and
  260. FTP Software plan to host the Windows Sock-A-Thon II in Boston
  261. February '93.
  262.  
  263. Without the contributions of the individuals and corporations involved
  264. in the working group, Windows Sockets would never have been as
  265. thoroughly reviewed and completed as quickly. In just one year,
  266. several
  267. competitors in the networking business developed a useful
  268. specification with something to show for it! Many thanks to all which
  269. participated, either in person or on e-mail to the Windows Sockets
  270. effort. The authors would like to thank everyone who participated in
  271. any way, and apologize in advance for anyone we have omitted.
  272.  
  273. List of contributors:
  274.  
  275. Martin Hall    (Chairman)     JSB Corporation
  276.      martinh@jsbus.com
  277. Mark Towfiq    (Coordinator)  Microdyne Corporation
  278.      towfiq@microdyne.com
  279. Geoff Arnold   (Editor 1.0)   Sun Microsystems
  280.      geoff@east.sun.com
  281. David Treadwell     (Editor 1.1)   Microsoft Corporation
  282.      davidtr@microsoft.com
  283. Henry Sanders            Microsoft Corporation
  284.      henrysa@microsoft.com
  285.  
  286. J. Allard           Microsoft           jallard@microsoft.
  287.                     Corporation         com
  288. Chris Arap-Bologna  Distinct            chris@distinct.com
  289. Larry Backman       FTP Software        backman@ftp.com
  290. Alistair Banks      Microsoft           alistair@microsoft
  291.                     Corporation         .com
  292. Rob Barrow          JSB Corporation     robb@jsb.co.uk
  293. Carl Beame          Beame & Whiteside   beame@mcmaster,ca
  294. Dave Beaver         Microsoft           dbeaver@microsoft.
  295.                     Corporation         com
  296.                                   1
  297.  
  298.  
  299.  
  300. 2 Introduction
  301.  
  302. Amatzia BenArtzi    NetManage, Inc.     amatzia@netmanage.
  303.                                         com
  304. Mark Beyer          Ungermann-Bass      mbeyer@ub.com
  305. Nelson Bolyard      Silicon Graphics,   nelson@sgi.com
  306.                     Inc.
  307. Pat Bonner          Hewlett-Packard     p_bonner@cnd.hp.co
  308.                                         m
  309. Derek Brown         FTP Software        db@wco.ftp.com
  310. Malcolm Butler      ICL                 mcab@oasis.icl.co.
  311.                                         uk
  312. Mike Calbaum        Fronteir            mike@frontiertech.
  313.                     Technologies        com
  314. Isaac Chan          Microsoft           isaacc@microsoft.c
  315.                     Corporation         om
  316. Khoji Darbani       Informix            khoji@informix.com
  317. Nestor Fesas        Hughes LAN Systems  nestor@hls.com
  318. Karanja Gakio       FTP Software        karanja@ftp.com
  319. Vikas Garg          Distinct            vikas@distinct.com
  320. Gary Gere           Gupta               ggere@gupta.com
  321. Jim Gilroy          Microsoft           jamesg@microsoft.c
  322.                     Corporation         om
  323. Bill Hayes          Hewlett-Packard     billh@hpchdpc.cnd.
  324.                                         hp.com
  325. Paul Hill           MIT                 pbh@athena.mit.edu
  326. Tmima Koren         Net Manage, Inc.    tmima@netmanage.co
  327.                                         m
  328. Hoek Law            Citicorp            law@dcc.tti.com
  329. Graeme Le Roux      Moresdawn P/L       -
  330. Kevin Lewis         Novell              kevinl@novell.com
  331. Roger Lin           3Com                roger_lin@3mail.3c
  332.                                         om.com
  333. Terry Lister        Hewlett-Packard     tel@cnd.hp.com
  334. Jeng Long Jiang     Wollongong          long@twg.com
  335. Lee Murach          Network Research    lee@nrc.com
  336. Pete Ostenson       Microsoft           peteo@microsoft.co
  337.                     Corporation         m
  338. David Pool          Spry, Inc.          dave@spry.com
  339. Bob Quinn           FTP Software        rcq@ftp.com
  340. Glenn Reitsma       Hughes LAN Systems  glennr@hls.com
  341. Brad Rice           Age                 rice@age.com
  342. Allen Rochkind      3Com                -
  343. Jonathan Rosen      IBM                 jrosen@vnet.ibm.co
  344.                                         m
  345. Steve Stokes        Novell              stoke@novell.com
  346. Joseph Tsai         3Com                joe_tsai@3mail.3co
  347.                                         m.com
  348. James Van Bokkelen  FTP Software        jbvb@ftp.com
  349. Miles Wu            Wollongong          wu@twg.com
  350. Boris Yanovsky      NetManage, Inc.     boris@netmanage.co
  351.                                         m
  352.  
  353.  
  354.  
  355.                                                         Introduction 3
  356.  
  357. 1.  INTRODUCTION
  358.  
  359. 1.1 What is Windows Sockets?
  360. The Windows Sockets specification defines a network programming
  361. interface for Microsoft Windows1 which is based on the "socket"
  362. paradigm popularized in the Berkeley Software Distribution (BSD) from
  363. the University of California at Berkeley.  It encompasses both
  364. familiar Berkeley socket style routines and a set of Windows-specific
  365. extensions designed to allow the programmer to take advantage of the
  366. message-driven nature of Windows.
  367.  
  368. The Windows Sockets Specification is intended to provide a single API
  369. to which application developers can program and multiple network
  370. software vendors can conform.  Furthermore, in the context of a
  371. particular version of Microsoft Windows, it defines a binary interface
  372. (ABI) such that an application written to the Windows Sockets API can
  373. work with a conformant protocol implementation from any network
  374. software vendor.  This specification thus defines the library calls
  375. and associated semantics to which an application developer can program
  376. and which a network software vendor can implement.
  377.  
  378. Network software which conforms to this Windows Sockets specification
  379. will be considered "Windows Sockets Compliant".  Suppliers of
  380. interfaces which are "Windows Sockets Compliant" shall be referred to
  381. as "Windows Sockets Suppliers".  To be Windows Sockets Compliant, a
  382. vendor must implement 100% of this Windows Sockets specification.
  383.  
  384. Applications which are capable of operating with any "Windows Sockets
  385. Compliant" protocol implementation will be considered as having a
  386. "Windows Sockets Interface" and will be referred to as "Windows
  387. Sockets Applications".
  388.  
  389. This version of the Windows Sockets specification defines and
  390. documents the use of the API in conjunction with the Internet Protocol
  391. Suite (IPS, generally referred to as TCP/IP).  Specifically, all
  392. Windows Sockets implementations support both stream (TCP) and datagram
  393. (UDP) sockets.
  394.  
  395. While the use of this API with alternative protocol stacks is not
  396. precluded (and is expected to be the subject of future revisions of
  397. the specification), such usage is beyond the scope of this version of
  398. the specification.
  399.  
  400.  
  401. 1.2 Berkeley Sockets
  402. The Windows Sockets Specification has been built upon the Berkeley
  403. Sockets programming model which is the de facto standard for TCP/IP
  404. networking.  It is intended to provide a high degree of familiarity
  405. for programmers who are used to programming with sockets in UNIX2 and
  406. other environments, and to simplify the task of porting existing
  407. sockets-based source code.  The Windows Sockets API is consistent with
  408. release 4.3 of the Berkeley Software Distribution (4.3BSD).
  409.  
  410.  
  411.                     
  412. 1 Windows is a trademark of Microsoft Corporation.
  413. 2 UNIX is a trademark of Unix System Laboratories, Inc.
  414.                                   3
  415.  
  416.  
  417.  
  418. 4 Introduction
  419.  
  420. Portions of the Windows Sockets specification are derived from
  421. material which is Copyright (c) 1982-1986 by the Regents of the
  422. University of California.  All rights are reserved.  The Berkeley
  423. Software License Agreement specifies the terms and conditions for
  424. redistribution.
  425.  
  426.  
  427. 1.3 Microsoft Windows and Windows-specific extensions
  428. This API is intended to be usable within all implementations and
  429. versions of Microsoft Windows from Microsoft Windows Version 3.0
  430. onwards.  It thus provides for Windows Sockets implementations and
  431. Windows Sockets applications in both 16 and 32 bit operating
  432. environments.
  433.  
  434. Windows Sockets makes provisions for multithreaded Windows processes.
  435. A process contains one or more threads of execution.  In the Windows
  436. 3.1 non-multithreaded world, a task corresponds to a process with a
  437. single thread.  All references to threads in this document refer to
  438. actual "threads" in multithreaded Windows environments.  In non
  439. multithreaded environments (such as Windows 3.0), use of the term
  440. thread refers to a Windows process.
  441.  
  442. The Microsoft Windows extensions included in Windows Sockets are
  443. provided to allow application developers to create software which
  444. conforms to the Windows programming model.  It is expected that this
  445. will facilitate the creation of robust and high-performance
  446. applications, and will improve the cooperative multitasking of
  447. applications within non-preemptive versions of Windows.  With the
  448. exception of WSAStartup() and WSACleanup() their use is not mandatory.
  449.  
  450.  
  451. 1.4 The Status of this Specification
  452.  
  453. Windows Sockets is an independent specification which was created and
  454. exists for the benefit of application developers and network vendors
  455. and, indirectly, computer users. Each published (non-draft) version of
  456. this specification  represents a fully workable API for implementation
  457. by network vendors and programming use by application developers.
  458. Discussion of this specification and  suggested improvements continue
  459. and are welcomed. Such discussion occurs mainly via the Internet
  460. electronic mail forum winsock@microdyne.com. Meetings of  interested
  461. parties occur on an irregular basis. Details of these meetings are
  462. publicized to the electronic mail forum.
  463.  
  464.  
  465. 1.5 Revision History
  466. 1.5.1 Windows Sockets Version 1.0
  467. Windows Sockets Version 1.0 represented the results of considerable
  468. work within  the vendor and user community as discussed in Appendix C.
  469. This version of  the specification was released in order that network
  470. software suppliers and  application developers could begin to
  471. construct implementations and
  472. applications  which conformed to the Windows Sockets standard.
  473.  
  474. 1.5.2 Windows Sockets Version 1.1
  475. Windows Sockets Version 1.1 follows the guidelines and structure laid
  476. out by version 1.0, making changes only where absolutely necessary as
  477.  
  478.  
  479.  
  480.                                                         Introduction 5
  481.  
  482. indicated by the experiences of a number of companies that created
  483. Windows Sockets implementations based on the version 1.0
  484. specification.  Version 1.1 contains several clarifications and minor
  485. fixes to version 1.0.  Additionally, the following more significant
  486. changes were incorporated into version 1.1:
  487.  
  488.      o Inclusion of the gethostname() routine to simplify retrieval of
  489.      the host's name and address.
  490.  
  491.      o Definition of DLL ordinal values below 1000 as reserved for
  492.      Windows Sockets and ordinals above 1000 as unrestricted.  This
  493.      allows Windows Sockets vendors to include private interfaces to
  494.      their DLLs without risking that the ordinals chosen will conflict
  495.      with a future version of Windows Sockets.
  496.  
  497.      o Addition of a reference count to WSAStartup() and WSACleanup(),
  498.      requiring correspondences between the calls.  This allows
  499.      applications and third-party DLLs to make use of a Windows
  500.      Sockets implementation without being concerned about the calls to
  501.      these APIs made by the other.
  502.  
  503.      o Change of return type of inet_addr() from struct in_addr to
  504.      unsigned long.  This was required due to different handling of
  505.      four-byte structure returns between the Microsoft and Borland C
  506.      compilers.
  507.  
  508.      o Change of WSAAsyncSelect() semantics from "edge-triggered" to
  509.      "level-triggered".  The level-triggered semantics significantly
  510.      simplify an application's use of this routine.
  511.  
  512.      o Change the ioctlsocket() FIONBIO semantics to fail if a
  513.      WSAAsyncSelect() call is outstanding on the socket.
  514.  
  515.      o Addition of the TCP_NODELAY socket option for RFC 1122
  516.      conformance.
  517.  
  518. All changes between the 1.0 and 1.1 specifications are flagged with
  519. change bars at the left of the page.
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.                                   5
  540.  
  541.  
  542.  
  543. 6 Programming with Sockets
  544.  
  545.  
  546. 2.  PROGRAMMING WITH SOCKETS
  547.  
  548. 2.1 Windows Sockets Stack Installation Checking
  549. To detect the presence of one (or many) Windows Sockets
  550. implementations on a system, an application which has been linked with
  551. the Windows Sockets Import Library may simply call the WSAStartup()
  552. routine.  If an application wishes to be a little more sophisticated
  553. it can examine the $PATH environment variable and search for instances
  554. of Windows Sockets implementations (WINSOCK.DLL).  For each instance
  555. it can issue a LoadLibrary() call and use the WSAStartup() routine to
  556. discover implementation specific data.
  557.  
  558. This version of the Windows Sockets specification does not attempt to
  559. address explicitly the issue of multiple concurrent Windows Sockets
  560. implementations.  Nothing in the specification should be interpreted
  561. as restricting multiple Windows Sockets DLLs from being present and
  562. used concurrently by one or more Windows Sockets applications.
  563.  
  564. For further details of where to obtain Windows Sockets components, see
  565. Appendix B.2.
  566.  
  567.  
  568. 2.2 Sockets
  569. The following material is derived from the document "An Advanced
  570. 4.3BSD Interprocess Communication Tutorial" by Samuel J. Leffler,
  571. Robert S. Fabry, William N. Joy, Phil Lapsley, Steve Miller, and Chris
  572. Torek.
  573.  
  574. 2.2.1 Basic concepts
  575. The basic building block for communication is the socket.  A socket is
  576. an endpoint of communication to which a name may be bound.  Each
  577. socket in use has a type and an associated process.  Sockets exist
  578. within communication domains.  A communication domain is an
  579. abstraction introduced to bundle common properties of threads
  580. communicating through sockets.  Sockets normally exchange data only
  581. with sockets in the same domain (it may be possible to cross domain
  582. boundaries, but only if some translation process is performed).  The
  583. Windows Sockets facilities support a single communication domain: the
  584. Internet domain, which is used by processes which communicate using
  585. the Internet Protocol Suite.  (Future versions of this specification
  586. may include additional domains.)
  587.  
  588. Sockets are typed according to the communication properties visible to
  589. a user.  Applications are presumed to communicate only between sockets
  590. of the same type, although there is nothing that prevents
  591. communication between sockets of different types should the underlying
  592. communication protocols support this.
  593.  
  594. Two types of sockets currently are available to a user.  A stream
  595. socket provides for the bi-directional, reliable, sequenced, and
  596. unduplicated flow of data without record boundaries.
  597.  
  598. A datagram socket supports bi-directional flow of data which is not
  599. promised to be sequenced, reliable, or unduplicated.  That is, a
  600. process receiving messages on a datagram socket may find messages
  601. duplicated, and, possibly, in an order different from the order in
  602.  
  603.  
  604.  
  605.                                             Programming with Sockets 7
  606.  
  607. which it was sent.  An important characteristic of a datagram socket
  608. is that record boundaries in data are preserved.  Datagram sockets
  609. closely model the facilities found in many contemporary packet
  610. switched networks such as Ethernet.
  611.  
  612. 2.2.2 Client-server model
  613. The most commonly used paradigm in constructing distributed
  614. applications is the client/server model.  In this scheme client
  615. applications request services from a server application.  This implies
  616. an asymmetry in establishing communication between the client and
  617. server.
  618.  
  619. The client and server require a well-known set of conventions before
  620. service may be rendered (and accepted).  This set of conventions
  621. comprises a protocol which must be implemented at both ends of a
  622. connection.  Depending on the situation, the protocol may be symmetric
  623. or asymmetric.  In a symmetric protocol, either side may play the
  624. master or slave roles.  In an asymmetric protocol, one side is
  625. immutably recognized as the master, with the other as the slave.  An
  626. example of a symmetric protocol is the TELNET protocol used in the
  627. Internet for remote terminal emulation.  An example of an asymmetric
  628. protocol is the Internet file transfer protocol, FTP.  No matter
  629. whether the specific protocol used in obtaining a service is symmetric
  630. or asymmetric, when accessing a service there is a "client process''
  631. and a "server process''.
  632.  
  633. A server application normally listens at a well-known address for
  634. service requests.  That is, the server process remains dormant until a
  635. connection is requested by a client's connection to the server's
  636. address.  At such a time the server process "wakes up'' and services
  637. the client, performing whatever appropriate actions the client
  638. requests of it.  While connection-based services are the norm, some
  639. services are based on the use of datagram sockets.
  640.  
  641. 2.2.3 Out-of-band data
  642.  
  643.  
  644.  
  645. Note: The following discussion of out-of-band data, also referred to
  646. as TCP Urgent data,  follows the model used in the Berkeley software
  647. distribution.  Users and implementors should be aware of the fact that
  648. there are at present two conflicting interpretations of RFC 793 (in
  649. which the concept is introduced), and that the implementation of out-
  650. of-band data in the Berkeley Software Distribution does not conform to
  651. the Host Requirements laid down in RFC 1122.  To minimize
  652. interoperability problems, applications writers are advised not to use
  653. out-of-band data unless this is required in order to interoperate with
  654. an existing service.  Windows Sockets suppliers are urged to document
  655. the out-of-band semantics (BSD or RFC 1122) which their product
  656. implements.  It is beyond the scope of this specification to mandate a
  657. particular set of semantics for out-of-band data handling.
  658.  
  659.  
  660.  
  661.  
  662. The stream socket abstraction includes the notion of "out of band''
  663. data.  Out-of-band data is a logically independent transmission
  664.                                   7
  665.  
  666.  
  667.  
  668. 8 Programming with Sockets
  669.  
  670. channel associated with each pair of connected stream sockets.  Out-
  671. of-band data is delivered to the user independently of normal data.
  672. The abstraction defines that the out-of-band data facilities must
  673. support the reliable delivery of at least one out-of-band message at a
  674. time.  This message may contain at least one byte of data, and at
  675. least one message may be pending delivery to the user at any one time.
  676. For communications protocols which support only in-band signaling
  677. (i.e.  the urgent data is delivered in sequence with the normal data),
  678. the system normally extracts the data from the normal data stream and
  679. stores it separately.  This allows users to choose between receiving
  680. the urgent data in order and receiving it out of sequence without
  681. having to buffer all the intervening data.  It is possible to "peek''
  682. at out-of-band data.
  683.  
  684. An application may prefer to process out-of-band data "in-line", as
  685. part of the normal data stream.  This is achieved by setting the
  686. socket option SO_OOBINLINE (see section 4.1.21, setsockopt()).  In
  687. this case, the application may wish to determine whether any of the
  688. unread data is "urgent" (the term usually applied to in-line out-of-
  689. band data).  To facilitate this, the Windows Sockets implementation
  690. will maintain a logical "mark" in the data stream indicate the point
  691. at which the out-of-band data was sent.  An application can use the
  692. SIOCATMARK ioctlsocket() command (see section 4.1.12) to determine
  693. whether there is any unread data preceding the mark.  For example, it
  694. might use this to resynchronize with its peer by ensuring that all
  695. data up to the mark in the data stream is discarded when appropriate.
  696.  
  697. The WSAAsyncSelect() routine is particularly well suited to handling
  698. notification of the presence of out-of-band-data.
  699.  
  700. 2.2.4 Broadcasting
  701. By using a datagram socket, it is possible to send broadcast packets
  702. on many networks supported by the system.  The network itself must
  703. support broadcast: the system provides no simulation of broadcast in
  704. software.  Broadcast messages can place a high load on a network,
  705. since they force every host on the network to service them.
  706. Consequently, the ability to send broadcast packets has been limited
  707. to sockets which are explicitly marked as allowing broadcasting.
  708. Broadcast is typically used for one of two reasons: it is desired to
  709. find a resource on a local network without prior knowledge of its
  710. address, or important functions such as routing require that
  711. information be sent to all accessible neighbors.
  712.  
  713. The destination address of the message to be broadcast depends on the
  714. network(s) on which the message is to be broadcast.  The Internet
  715. domain supports a shorthand notation for broadcast on the local
  716. network, the address INADDR_BROADCAST.  Received broadcast messages
  717. contain the senders address and port, as datagram sockets must be
  718. bound before use.
  719.  
  720. Some types of network support the notion of different types of
  721. broadcast.  For example, the IEEE 802.5 token ring architecture
  722. supports the use of link-level broadcast indicators, which control
  723. whether broadcasts are forwarded by bridges.  The Windows Sockets
  724. specification does not provide any mechanism whereby an application
  725. can determine the type of underlying network, nor any way to control
  726. the semantics of broadcasting.
  727.  
  728.  
  729.  
  730.                                             Programming with Sockets 9
  731.  
  732.  
  733.  
  734. 2.3 Byte Ordering
  735. The Intel byte ordering is like that of the DEC VAX3, and therefore
  736. differs from the Internet and 680004-type processor byte ordering.
  737. Thus care must be taken to ensure correct orientation.
  738.  
  739. Any reference to IP addresses or port numbers passed to or from a
  740. Windows Sockets routine must be in network order.  This includes the
  741. IP address and port fields of a struct sockaddr_in (but not the
  742. sin_family field).
  743.  
  744. Consider an application which normally contacts a server on the TCP
  745. port corresponding to the "time" service, but which provides a
  746. mechanism for the user to specify that an alternative port is to be
  747. used.  The port number returned by getservbyname() is already in
  748. network order, which is the format required constructing an address,
  749. so no translation is required.  However if the user elects to use a
  750. different port, entered as an integer, the application must convert
  751. this from host to network order (using the htons() function) before
  752. using it to construct an address.  Conversely, if the application
  753. wishes to display the number of the port within an address (returned
  754. via, e.g., getpeername()), the port number must be converted from
  755. network to host order (using ntohs()) before it can be displayed.
  756.  
  757. Since the Intel and Internet byte orders are different, the
  758. conversions described above are unavoidable.  Application writers are
  759. cautioned that they should use the standard conversion functions
  760. provided as part of the Windows Sockets API rather than writing their
  761. own conversion code, since future implementations of Windows Sockets
  762. are likely to run on systems for which the host order is identical to
  763. the network byte order.  Only applications which use the standard
  764. conversion functions are likely to be portable.
  765.  
  766.  
  767. 2.4 Socket Options
  768. The socket options supported by Windows Sockets are listed in the
  769. pages describing setsockopt() and getsockopt().  A Windows Sockets
  770. implementation must recognize all of these options, and (for
  771. getsockopt()) return plausible values for each.  The default value for
  772. each option is shown in the following table.
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.                     
  787. 3 VAX is a trademark of Digital Equipment Corporation.
  788. 4 68000 is a trademark of Motorola, Inc.
  789.                                   9
  790.  
  791.  
  792.  
  793. 10 Programming with Sockets
  794.  
  795.  
  796. Value        Type     Meaning             Default      Not
  797.                                                        e
  798.  
  799.  
  800.  
  801. SO_ACCEPTCO  BOOL     Socket is           FALSE
  802.  N
  803. N                     listen()ing.        unless a
  804.                                           listen()
  805.                                           has been
  806.                                           performed
  807.  
  808. SO_BROADCAS  BOOL     Socket is           FALSE
  809. T                     configured for the
  810.                       transmission of
  811.                       broadcast
  812.                       messages.
  813.  
  814. SO_DEBUG     BOOL     Debugging is        FALSE        (i)
  815.                       enabled.
  816.  
  817. SO_DONTLING  BOOL     If true, the        TRUE
  818. ER                    SO_LINGER option
  819.                       is disabled.
  820.  
  821. SO_DONTROUT  BOOL     Routing is          FALSE        (i)
  822. E                     disabled.
  823.  
  824. SO_ERROR     int      Retrieve error      0
  825.                       status and clear.
  826.  
  827. SO_KEEPALIV  BOOL     Keepalives are      FALSE
  828. E                     being sent.
  829.  
  830. SO_LINGER    struct   Returns the         l_onoff is
  831.              linger   current linger      0
  832.              FAR *    options.
  833.  
  834. SO_OOBINLIN  BOOL     Out-of-band data    FALSE
  835. E                     is being received
  836.                       in the normal data
  837.                       stream.
  838.  
  839. SO_RCVBUF    int      Buffer size for     Implementat  (i)
  840.                       receives            ion
  841.                                           dependent
  842.  
  843. SO_REUSEADD  BOOL     The address to      FALSE
  844. R                     which this socket
  845.                       is bound can be
  846.                       used by others.
  847.  
  848. SO_SNDBUF    int      Buffer size for     Implementat  (i)
  849.                       sends               ion
  850.                                           dependent
  851.  
  852.  
  853.  
  854.                                            Programming with Sockets 11
  855.  
  856.  
  857. SO_TYPE      int      The type of the     As created
  858.                       socket (e.g.        via
  859.                       SOCK_STREAM).       socket()
  860.  
  861. TCP_NODELAY  BOOL     Disables the Nagle  Implementat
  862.                       algorithm for send  ion
  863.                       coalescing.         dependent
  864.  
  865.  
  866. Notes:
  867. (i)       An implementation may silently ignore this option on
  868.           setsockopt() and return a constant value for getsockopt(),
  869.           or it may accept a value for setsockopt() and return the
  870.           corresponding value in getsockopt() without using the value
  871.           in any way.
  872.  
  873.  
  874.  
  875. 2.5 Database Files
  876. The getXbyY()  and WSAAsyncGetXByY() classes of routines are provided
  877.              5
  878. for retrieving network specific information.  The getXbyY() routines
  879. were originally designed (in the first Berkeley UNIX releases) as
  880. mechanisms for looking up information in text databases.  Although the
  881. information may be retrieved by the Windows Sockets implementation in
  882. different ways, a Windows Sockets application requests such
  883. information in a consistent manner through either the getXbyY() or the
  884. WSAAsyncGetXByY() class of routines.
  885.  
  886.  
  887. 2.6 Deviation from Berkeley Sockets
  888. There are a few limited instances where the Windows Sockets API has
  889. had to divert from strict adherence to the Berkeley conventions,
  890. usually because of difficulties of implementation in a Windows
  891. environment.
  892.  
  893. 2.6.1 socket data type and error values
  894. A new data type, SOCKET, has been defined.  The definition of this
  895. type was necessary for future enhancements to the Windows Sockets
  896. specification, such as being able to use sockets as file handles in
  897. Windows NT .  Definition of this type also facilitates porting of
  898.           6
  899. applications to a Win/32 environment, as the type will automatically
  900. be promoted from 16 to 32 bits.
  901.  
  902. In UNIX, all handles, including socket handles, are small, non-
  903. negative integers, and some applications make assumptions that this
  904. will be true.  Windows Sockets handles have no restrictions, other
  905. than that the value INVALID_SOCKET is not a valid socket.  Socket
  906. handles may take any value in the range 0 to INVALID_SOCKET-1.
  907.  
  908.  
  909.  
  910.                     
  911.   This specification uses the function name getXbyY() to represent the
  912. 5
  913. set of routines gethostbyaddr(), gethostbyname(), etc. Similarly
  914. WSAAsyncGetXByY() represents WSAAsyncGetHostByAddr(), etc.
  915.   NT and Windows/NT are trademarks of Microsoft Corporation.
  916. 6
  917.                                   11
  918.  
  919.  
  920.  
  921. 12 Programming with Sockets
  922.  
  923. Because the SOCKET type is unsigned, compiling existing source code
  924. from, for example, a UNIX environment may lead to compiler warnings
  925. about signed/unsigned data type mismatches.
  926.  
  927. This means, for example, that checking for errors when the socket()
  928. and accept() routines return should not be done by comparing the
  929. return value with -1, or seeing if the value is negative (both common,
  930. and legal, approaches in BSD).  Instead, an application should use the
  931. manifest constant INVALID_SOCKET as defined in winsock.h.  For
  932. example:
  933.      TYPICAL BSD STYLE:
  934.           s = socket(...);
  935.           if (s == -1)   /* or s < 0 */
  936.                {...}
  937.  
  938.      PREFERRED STYLE:
  939.           s = socket(...);
  940.           if (s == INVALID_SOCKET)
  941.                {...}
  942.  
  943. 2.6.2 select() and FD_*
  944. Because a SOCKET is no longer represented by the UNIX-style "small
  945. non-negative integer", the implementation of the select() function was
  946. changed in the Windows Sockets API.  Each set of sockets is still
  947. represented by the fd_set type, but instead of being stored as a
  948. bitmask the set is implemented as an array of SOCKETs.  To avoid
  949. potential problems, applications must adhere to the use of the FD_XXX
  950. macros to set, initialize, clear, and check the fd_set structures.
  951.  
  952. 2.6.3 Error codes - errno, h_errno & WSAGetLastError()
  953. Error codes set by the Windows Sockets implementation are NOT made
  954. available via the errno variable.  Additionally, for the getXbyY()
  955. class of functions, error codes are NOT made available via the h_errno
  956. variable.  Instead, error codes are accessed by using the
  957. WSAGetLastError() API described in section 4.3.11.  This function is
  958. provided in Windows Sockets as a precursor (and eventually an alias)
  959. for the Win32 function GetLastError().  This is intended to provide a
  960. reliable way for a thread in a multi-threaded process to obtain per-
  961. thread error information.
  962.  
  963. For compatibility with BSD, an application may choose to include a
  964. line of the form:
  965.  
  966.           #define errno WSAGetLastError()
  967.  
  968. This will allow networking code which was written to use the global
  969. errno to work correctly in a single-threaded environment.  There are,
  970. obviously, some drawbacks.  If a source file includes code which
  971. inspects errno for both socket and non-socket functions, this
  972. mechanism cannot be used.  Furthermore, it is not possible for an
  973. application to assign a new value to errno.  (In Windows Sockets the
  974. function WSASetLastError() may be used for this purpose.)
  975.  
  976.  
  977.  
  978.                                            Programming with Sockets 13
  979.  
  980.      TYPICAL BSD STYLE:
  981.           r = recv(...);
  982.           if (r == -1
  983.               && errno == EWOULDBLOCK)
  984.                {...}
  985.  
  986.      PREFERRED STYLE:
  987.           r = recv(...);
  988.           if (r == -1       /* (but see below) */
  989.               && WSAGetLastError() == EWOULDBLOCK)
  990.                {...}
  991.  
  992. Although error constants consistent with 4.3 Berkeley Sockets are
  993. provided for compatibility purposes, applications should, where
  994. possible, use the "WSA" error code definitions.  For example, a more
  995. accurate version of the above source code fragment is:
  996.  
  997.           r = recv(...);
  998.           if (r == -1       /* (but see below) */
  999.               && WSAGetLastError() == WSAEWOULDBLOCK)
  1000.                {...}
  1001.  
  1002. 2.6.4 Pointers
  1003. All pointers used by applications with Windows Sockets should be FAR.
  1004. To facilitate this, data type definitions such as LPHOSTENT are
  1005. provided.
  1006.  
  1007. 2.6.5 Renamed functions
  1008. In two cases it was necessary to rename functions which are used in
  1009. Berkeley Sockets in order to avoid clashes with other APIs.
  1010.  
  1011. 2.6.5.1 close() & closesocket()
  1012. In Berkeley Sockets, sockets are represented by standard file
  1013. descriptors, and so the close() function can be used to close sockets
  1014. as well as regular files.  While nothing in the Windows Sockets API
  1015. prevents an implementation from using regular file handles to identify
  1016. sockets, nothing requires it either.  Socket descriptors are not
  1017. presumed to correspond to regular file handles, and file operations
  1018. such as read(), write(), and close() cannot be assumed to work
  1019. correctly when applied to sockets.  Sockets must be closed by using
  1020. the closesocket() routine.  Using the close() routine to close a
  1021. socket is incorrect and the effects of doing so are undefined by this
  1022. specification.
  1023.  
  1024. 2.6.5.1 ioctl() & ioctlsocket()
  1025. Various C language run-time systems use the ioctl() routine for
  1026. purposes unrelated to Windows Sockets.  For this reason we have
  1027. defined the routine ioctlsocket() which is used to handle socket
  1028. functions which in the Berkeley Software Distribution are performed
  1029. using ioctl() and fcntl().
  1030.  
  1031. 2.6.6 Blocking routines & EINPROGRESS
  1032. Although blocking operations on sockets are supported under Windows
  1033. Sockets, their use is strongly discouraged.  Programmers who are
  1034. constrained to use blocking mode  for example, as part of an existing
  1035. application which is to be ported  should be aware of the semantics
  1036.  
  1037.                                   13
  1038.  
  1039.  
  1040.  
  1041. 14 Programming with Sockets
  1042.  
  1043. of blocking operations in Windows Sockets.  See section 3.1.1 for more
  1044. details.
  1045.  
  1046. 2.6.7 Maximum number of sockets supported
  1047. The maximum number of sockets supported by a particular Windows
  1048. Sockets supplier is implementation specific.  An application should
  1049. make no assumptions about the availability of a certain number of
  1050. sockets.  This topic is addressed further in section 4.3.15,
  1051. WSAStartup().  However, independent of the number of sockets supported
  1052. by a particular implementation is the issue of the maximum number of
  1053. sockets which an application can actually make use of.
  1054.  
  1055. The maximum number of sockets which a Windows Sockets application can
  1056. make use of is determined at compile time by the manifest constant
  1057. FD_SETSIZE.  This value is used in constructing the fd_set structures
  1058. used in select() (see section 4.1.18).  The default value in winsock.h
  1059. is 64.  If an application is designed to be capable of working with
  1060. more than 64 sockets, the implementor should define the manifest
  1061. FD_SETSIZE in every source file before including winsock.h.  One way
  1062. of doing this may be to include the definition within the compiler
  1063. options in the makefile, for example adding  -DFD_SETSIZE=128 as an
  1064. option to the compiler command line for Microsoft C.  It must be
  1065. emphasized that defining FD_SETSIZE as a particular value has no
  1066. effect on the actual number of sockets provided by a Windows Sockets
  1067. implementation.
  1068.  
  1069. 2.6.8 Include files
  1070. For ease of portability of existing Berkeley sockets based source
  1071. code, a number of standard Berkeley include files are supported.
  1072. However, these Berkeley header files merely include the winsock.h
  1073. include file, and it is therefore sufficient (and recommended) that
  1074. Windows Sockets application source files should simply include
  1075. winsock.h.
  1076.  
  1077. 2.6.9 Return values on API failure
  1078. The manifest constant SOCKET_ERROR is provided for checking API
  1079. failure.  Although use of this constant is not mandatory, it is
  1080. recommended.  The following example illustrates the use of the
  1081. SOCKET_ERROR constant:
  1082.  
  1083.      TYPICAL BSD STYLE:
  1084.           r = recv(...);
  1085.           if (r == -1     /* or r < 0 */
  1086.               && errno == EWOULDBLOCK)
  1087.                {...}
  1088.      PREFERRED STYLE:
  1089.           r = recv(...);
  1090.           if (r == SOCKET_ERROR
  1091.               && WSAGetLastError() == WSAEWOULDBLOCK)
  1092.                {...}
  1093.  
  1094. 2.6.10 Raw Sockets
  1095. The Windows Sockets specification does not mandate that a Windows
  1096. Sockets DLL support raw sockets, that is, sockets opened with
  1097. SOCK_RAW.  However, a Windows Sockets DLL is allowed and encouraged to
  1098. supply raw socket support.  A Windows Sockets-compliant application
  1099. that wishes to use raw sockets should attempt to open the socket with
  1100.  
  1101.  
  1102.  
  1103.                                            Programming with Sockets 15
  1104.  
  1105. the socket() call (see section 4.1.23), and if it fails either attempt
  1106. to use another socket type or indicate the failure to the user.
  1107.  
  1108.  
  1109. 2.7 Windows Sockets in Multithreaded Versions of Windows
  1110. The Windows Sockets interface is designed to work for both single-
  1111. threaded versions of Windows (such as Windows 3.1) and preemptive
  1112. multithreaded versions of Windows (such as Windows NT).  In a
  1113. multithreaded environment the sockets interface is basically the same,
  1114. but the author of a multithreaded application must be aware that it is
  1115. the responsibility of the application, not the Windows Sockets
  1116. implementation, to synchronize access to a socket between threads.
  1117. This is the same rule as applies to other forms of I/O such as file
  1118. I/O.  Failure to synchronize calls on a socket leads to unpredictable
  1119. results; for example if there are two simultaneous calls to send(),
  1120. there is no guarantee as to the order in which the data will be sent.
  1121.  
  1122. Closing a socket in one thread that has an outstanding blocking call
  1123. on the same socket in another thread will cause the blocking call to
  1124. fail with WSAEINTR, just as if the operation were canceled.  This also
  1125. applies if there is a select() call outstanding and the application
  1126. closes one of the sockets being selected.
  1127.  
  1128. There is no default blocking hook installed in preemptive
  1129. multithreaded versions of Windows.  This is because the machine will
  1130. not be blocked if a single application is waiting for an operation to
  1131. complete and hence not calling PeekMessage() or GetMessage() which
  1132. cause the application to yield in nonpremptive Windows.  However, for
  1133. backwards compatibility the WSASetBlockingHook() call is implemented
  1134. in multithreaded versions of Windows, and any application whose
  1135. behavior depends on the default blocking hook may install their own
  1136. blocking hook which duplicates the default hook's semantics, if
  1137. desired.
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.                                   15
  1163.  
  1164.  
  1165.  
  1166. 16 Socket Library Overview
  1167.  
  1168.  
  1169. 3.  SOCKET LIBRARY OVERVIEW
  1170.  
  1171. 3.1 Socket Functions
  1172. The Windows Sockets specification includes the following Berkeley-
  1173. style socket routines:
  1174.  
  1175.  
  1176.  
  1177.                                             Socket Library Overview 17
  1178.  
  1179.  
  1180. accept() *            An incoming connection is
  1181.                       acknowledged and associated with
  1182.                       an immediately created socket.
  1183.                       The original socket is returned
  1184.                       to the listening state.
  1185.  
  1186. bind()                Assign a local name to an unnamed
  1187.                       socket.
  1188.  
  1189. closesocket() *       Remove a socket from the per-
  1190.                       process object reference table.
  1191.                       Only blocks if SO_LINGER is set.
  1192.  
  1193. connect() *           Initiate a connection on the
  1194.                       specified socket.
  1195.  
  1196. getpeername()         Retrieve the name of the peer
  1197.                       connected to the specified
  1198.                       socket.
  1199.  
  1200. getsockname()         Retrieve the current name for the
  1201.                       specified socket
  1202.  
  1203. getsockopt()          Retrieve options associated with
  1204.                       the specified socket.
  1205.  
  1206. htonl()               Convert a 32-bit quantity from
  1207.                       host byte order to network byte
  1208.                       order.
  1209.  
  1210. htons()               Convert a 16-bit quantity from
  1211.                       host byte order to network byte
  1212.                       order.
  1213.  
  1214. inet_addr()           Converts a character string
  1215.                       representing a number in the
  1216.                       Internet standard ".'' notation
  1217.                       to an Internet address value.
  1218.  
  1219. inet_ntoa()           Converts an Internet address
  1220.                       value to an ASCII string in ".''
  1221.                       notation i.e.  "a.b.c.d''.
  1222.  
  1223. ioctlsocket()         Provide control for sockets.
  1224.  
  1225. listen()              Listen for incoming connections
  1226.                       on a specified socket.
  1227.  
  1228. ntohl()               Convert a 32-bit quantity from
  1229.                       network byte order to host byte
  1230.                       order.
  1231.  
  1232. ntohs()               Convert a 16-bit quantity from
  1233.                       network byte order to host byte
  1234.                       order.
  1235.  
  1236.                                   17
  1237.  
  1238.  
  1239.  
  1240. 18 Socket Library Overview
  1241.  
  1242.  
  1243. recv() *              Receive data from a connected
  1244.                       socket.
  1245.  
  1246. recvfrom() *          Receive data from either a
  1247.                       connected or unconnected socket.
  1248.  
  1249. select() *            Perform synchronous I/O
  1250.                       multiplexing.
  1251.  
  1252. send() *              Send data to a connected socket.
  1253.  
  1254. sendto() *            Send data to either a connected
  1255.                       or unconnected socket.
  1256.  
  1257. setsockopt()          Store options associated with the
  1258.                       specified socket.
  1259.  
  1260. shutdown()            Shut down part of a full-duplex
  1261.                       connection.
  1262.  
  1263. socket()              Create an endpoint for
  1264.                       communication and return a
  1265.                       socket.
  1266.  
  1267.  
  1268. * = The routine can block if acting on a blocking socket.
  1269.  
  1270. 3.1.1 Blocking/Non blocking & Data Volatility
  1271. One major issue in porting applications from a Berkeley sockets
  1272. environment to a Windows environment involves "blocking"; that is,
  1273. invoking a function which does not return until the associated
  1274. operation is completed.  The problem arises when the operation may
  1275. take an arbitrarily long time to complete: an obvious example is a
  1276. recv() which may block until data has been received from the peer
  1277. system.  The default behavior within the Berkeley sockets model is for
  1278. a socket to operate in a blocking mode unless the programmer
  1279. explicitly requests that operations be treated as non-blocking.  It is
  1280. strongly recommended that programmers use the nonblocking
  1281. (asynchronous) operations if at all possible, as they work
  1282. significantly better within the nonpreemptive Windows environment.
  1283. Use blocking operations only if absolutely necessary, and carefully
  1284. read and understand this section if you must use blocking operations.
  1285.  
  1286. Even on a blocking socket, some operations (e.g. bind(), getsockopt(),
  1287. getpeername()) can be completed immediately.  For such operations
  1288. there is no difference between blocking and non-blocking operation.
  1289. Other operations (e.g. recv()) may be completed immediately or may
  1290. take an arbitrary time to complete, depending on various transport
  1291. conditions.  When applied to a blocking socket, these operations are
  1292. referred to as blocking operations.  All routines which can block are
  1293. listed with an asterisk in the tables above and below.
  1294.  
  1295. Within a Windows Sockets implementation, a blocking operation which
  1296. cannot be completed immediately is handled as follows.  The DLL
  1297. initiates the operation, and then enters a loop in which it dispatches
  1298. any Windows messages (yielding the processor to another thread if
  1299.  
  1300.  
  1301.  
  1302.                                             Socket Library Overview 19
  1303.  
  1304. necessary) and then checks for the completion of the Windows Sockets
  1305. function.  If the function has completed, or if
  1306. WSACancelBlockingCall() has been invoked, the blocking function
  1307. completes with an appropriate result.  Refer to section 4.3.13,
  1308. WSASetBlockingHook(), for a complete description of this mechanism,
  1309. including pseudocode for the various functions.
  1310.  
  1311. If a Windows message is received for a process for which a blocking
  1312. operation is in progress, there is a risk that the application will
  1313. attempt to issue another Windows Sockets call.  Because of the
  1314. difficulty of managing this condition safely, the Windows Sockets
  1315. specification does not support such application behavior.  Two
  1316. functions are provided to assist the programmer in this situation.
  1317. WSAIsBlocking() may be called to determine whether or not a blocking
  1318. Windows Sockets call is in progress.  WSACancelBlockingCall() may be
  1319. called to cancel an in-progress blocking call, if any.  Any other
  1320. Windows Sockets function which is called in this situation will fail
  1321. with the error WSAEINPROGRESS.  It should be emphasized that this
  1322. restriction applies to both blocking and non-blocking operations.
  1323.  
  1324. Although this mechanism is sufficient for simple applications, it
  1325. cannot support the complex message-dispatching requirements of more
  1326. advanced applications (for example, those using the MDI model).  For
  1327. such applications, the Windows Sockets API includes the function
  1328. WSASetBlockingHook(), which allows the programmer to define a special
  1329. routine which will be called instead of the default message dispatch
  1330. routine described above.
  1331.  
  1332. The Windows Sockets DLL calls the blocking hook only if all of the
  1333. following are true: the routine is one which is defined as being able
  1334. to block, the specified socket is a blocking socket, and the request
  1335. cannot be completed immediately.  (A socket is set to blocking by
  1336. default, but the IOCTL FIONBIO and  WSAAsyncSelect() both set a socket
  1337. to nonblocking mode.)  If an application uses only non-blocking
  1338. sockets and uses the WSAAsyncSelect() and/or the WSAAsyncGetXByY()
  1339. routines instead of select() and the getXbyY() routines, then the
  1340. blocking hook will never be called and the application does not need
  1341. to be concerned with the reentrancy issues the blocking hook can
  1342. introduce.
  1343.  
  1344. If an application invokes an asynchronous or non-blocking operation
  1345. which takes a pointer to a memory object (e.g. a buffer, or a global
  1346. variable) as an argument, it is the responsibility of the application
  1347. to ensure that the object is available to the Windows Sockets
  1348. implementation throughout the operation.  The application must not
  1349. invoke any Windows function which might affect the mapping or
  1350. addressability of the memory involved.  In a multithreaded system, the
  1351. application is also responsible for coordinating access to the object
  1352. using appropriate synchronization mechanisms.  A Windows Sockets
  1353. implementation cannot, and will not, address these issues.  The
  1354. possible consequences of failing to observe these rules are beyond the
  1355. scope of this specification.
  1356.  
  1357.  
  1358. 3.2 Database Functions
  1359. The Windows Sockets specification defines the following "database"
  1360. routines.  As noted earlier, a Windows Sockets supplier may choose to
  1361.                                   19
  1362.  
  1363.  
  1364.  
  1365. 20 Socket Library Overview
  1366.  
  1367. implement these in a manner which does not depend on local database
  1368. files.  The pointer returned by certain database routines such as
  1369. gethostbyname() points to a structure which is allocated by the
  1370. Windows Sockets library.  The data which is pointed to is volatile and
  1371. is good only until the next Windows Sockets API call from that thread.
  1372. Additionally, the application must never attempt to modify this
  1373. structure or to free any of its components.  Only one copy of this
  1374. structure is allocated for a thread, and so the application should
  1375. copy any information which it needs before issuing any other Windows
  1376. Sockets API calls.
  1377.  
  1378.  
  1379.  
  1380. gethostbyaddr() *     Retrieve the name(s) and address
  1381.                       corresponding to a network
  1382.                       address.
  1383.  
  1384. gethostbyname() *     Retrieve the name(s) and address
  1385.                       corresponding to a host name.
  1386.  
  1387. gethostname()         Retrieve the name of the local
  1388.                       host.
  1389.  
  1390. getprotobyname() *    Retrieve the protocol name and
  1391.                       number corresponding to a
  1392.                       protocol name.
  1393.  
  1394. getprotobynumber() *  Retrieve the protocol name and
  1395.                       number corresponding to a
  1396.                       protocol number.
  1397.  
  1398. getservbyname() *     Retrieve the service name and
  1399.                       port corresponding to a service
  1400.                       name.
  1401.  
  1402. getservbyport() *     Retrieve the service name and
  1403.                       port corresponding to a port.
  1404.  
  1405.  
  1406.  
  1407.  
  1408. * = The routine can block under some circumstances.
  1409.  
  1410.  
  1411. 3.3 Microsoft Windows-specific Extension Functions
  1412. The Windows Sockets specification provides a number of extensions to
  1413. the standard set of Berkeley Sockets routines.  Principally, these
  1414. extended APIs allow message-based, asynchronous access to network
  1415. events.  While use of this extended API set is not mandatory for
  1416. socket-based programming  (with the exception of WSAStartup() and
  1417. WSACleanup()), it is recommended for conformance with the Microsoft
  1418. Windows programming paradigm.
  1419.  
  1420.  
  1421.  
  1422.                                             Socket Library Overview 21
  1423.  
  1424.  
  1425. WSAAsyncGetHostByAdd  A set of functions which provide
  1426. r()                   asynchronous
  1427.  
  1428. WSAAsyncGetHostByNam  versions of the standard Berkeley
  1429. e()
  1430.  
  1431. WSAAsyncGetProtoByNa  getXbyY() functions.  For
  1432. me()                  example, the
  1433.  
  1434. WSAAsyncGetProtoByNu  WSAAsyncGetHostByName() function
  1435. mber()                provides an
  1436.  
  1437. WSAAsyncGetServByNam  asynchronous message based
  1438. e()                   implementation of
  1439.  
  1440. WSAAsyncGetServByPor  the standard Berkeley
  1441. t()                   gethostbyname() function.
  1442.  
  1443. WSAAsyncSelect()      Perform asynchronous version of
  1444.                       select()
  1445.  
  1446. WSACancelAsyncReques  Cancel an outstanding instance of
  1447. t()                   a WSAAsyncGetXByY() function.
  1448.  
  1449. WSACancelBlockingCal  Cancel an outstanding "blocking"
  1450. l()                   API call
  1451.  
  1452. WSACleanup()          Sign off from the underlying
  1453.                       Windows Sockets DLL.
  1454.  
  1455. WSAGetLastError()     Obtain details of last Windows
  1456.                       Sockets API error
  1457.  
  1458. WSAIsBlocking()       Determine if the underlying
  1459.                       Windows Sockets DLL is already
  1460.                       blocking an existing call for
  1461.                       this thread
  1462.  
  1463. WSASetBlockingHook()  "Hook" the blocking method used
  1464.                       by the underlying Windows Sockets
  1465.                       implementation
  1466.  
  1467. WSASetLastError()     Set the error to be returned by a
  1468.                       subsequent WSAGetLastError()
  1469.  
  1470. WSAStartup()          Initialize the underlying Windows
  1471.                       Sockets DLL.
  1472.  
  1473. WSAUnhookBlockingHoo  Restore the original blocking
  1474. k()                   function
  1475.  
  1476.  
  1477. 3.3.1 Asynchronous select() Mechanism
  1478. The WSAAsyncSelect() API allows an application to register an interest
  1479. in one or many network events.  This API is provided to supersede the
  1480. need to do polled network I/O.  Any situation in which select() or
  1481.                                   21
  1482.  
  1483.  
  1484.  
  1485. 22 Socket Library Overview
  1486.  
  1487. non-blocking I/O routines (such as send() and recv()) are either
  1488. already used or are being considered is usually a candidate for the
  1489. WSAAsyncSelect() API.  When declaring interest in such condition(s),
  1490. you supply a window handle to be used for notification.  The
  1491. corresponding window then receives message-based notification of the
  1492. conditions in which you declared an interest.
  1493.  
  1494. WSAAsyncSelect() allows interest to be declared in the following
  1495. conditions for a particular socket:
  1496.      Socket readiness for reading
  1497.      Socket readiness for writing
  1498.      Out-of-band data ready for reading
  1499.      Socket readiness for accepting incoming connection
  1500.      Completion of non-blocking connect()
  1501.      Connection closure
  1502.  
  1503. 3.3.2 Asynchronous Support Routines
  1504. The asynchronous "database" functions allow applications to request
  1505. information in an asynchronous manner.  Some network implementations
  1506. and/or configurations perform network based operations to resolve such
  1507. requests.  The WSAAsyncGetXByY() functions allow application
  1508. developers to request services which would otherwise block the
  1509. operation of the whole Windows environment if the standard Berkeley
  1510. function were used.  The WSACancelAsyncRequest() function allows an
  1511. application to cancel any outstanding asynchronous request.
  1512.  
  1513. 3.3.3 Hooking Blocking Methods
  1514. As noted in section 3.1.1 above, Windows Sockets implements blocking
  1515. operations in such a way that Windows message processing can continue,
  1516. which may result in the application which issued the call receiving a
  1517. Windows message.  In certain situations an application may want to
  1518. influence or change the way in which this pseudo-blocking process is
  1519. implemented.  The WSASetBlockingHook() provides the ability to
  1520. substitute a named routine which the Windows Sockets implementation is
  1521. to use when relinquishing the processor during a "blocking" operation.
  1522.  
  1523. 3.3.4 Error Handling
  1524. For compatibility with thread-based environments, details of API
  1525. errors are obtained through the WSAGetLastError() API.  Although the
  1526. accepted "Berkeley-Style" mechanism for obtaining socket-based network
  1527. errors is via "errno", this mechanism cannot guarantee the integrity
  1528. of an error ID in a multi-threaded environment.  WSAGetLastError()
  1529. allows you to retrieve an error code on a per thread basis.
  1530.  
  1531. WSAGetLastError() returns error codes which avoid conflict with
  1532. standard Microsoft C error codes.  Certain error codes returned by
  1533. certain Windows Sockets routines fall into the standard range of error
  1534. codes as defined by Microsoft C.  If you are NOT using an application
  1535. development environment which defines error codes consistent with
  1536. Microsoft C, you are advised to use the Windows Sockets error codes
  1537. prefixed by "WSA" to ensure accurate error code detection.
  1538.  
  1539. Note that this specification defines a recommended set of error codes,
  1540. and lists the possible errors which may be returned as a result of
  1541. each function.  It may be the case in some implementations that other
  1542. Windows Sockets error codes will be returned in addition to those
  1543. listed, and applications should be prepared to handle errors other
  1544.  
  1545.  
  1546.  
  1547.                                             Socket Library Overview 23
  1548.  
  1549. than those enumerated under each API description.  However a Windows
  1550. Sockets implementation must not return any value which is not
  1551. enumerated in the table of legal Windows Sockets errors given in
  1552. Appendix A.1.
  1553.  
  1554. 3.3.5 Accessing a Windows Sockets DLL from an Intermediate DLL
  1555. A Windows Sockets DLL may be accessed both directly from an
  1556. application and through an "intermediate" DLL.  An example of such an
  1557. intermediate DLL would be a virtual network API layer that supports
  1558. generalized network functionality for applications and uses Windows
  1559. Sockets.  Such a DLL could be used by several applications
  1560. simultaneously, and the DLL must take special precautions with respect
  1561. to the WSAStartup() and WSACleanup() calls to ensure that these
  1562. routines are called in the context of each task that will make Windows
  1563. Sockets calls.  This is because the Windows Sockets DLL will need a
  1564. call to WSAStartup() for each task in order to set up task-specific
  1565. data structures, and a call to WSACleanup() to free any resources
  1566. allocated for the task.
  1567.  
  1568. There are (at least) two ways to accomplish this.  The simplest method
  1569. is for the intermediate DLL to have calls similar to WSAStartup() and
  1570. WSACleanup() that applications call as appropriate.  The DLL would
  1571. then call WSAStartup() or WSACleanup()  from within these routines.
  1572. Another mechanism is for the intermediate DLL to build a table of task
  1573. handles, which are obtained from the GetCurrentTask() Windows API, and
  1574. at each entry point into the intermediate DLL check whether
  1575. WSAStartup() has been called for the current task, then call
  1576. WSAStartup() if necessary.
  1577.  
  1578. If a DLL makes a blocking call and does not install its own blocking
  1579. hook, then the DLL author must be aware that control may be returned
  1580. to the application either by an application-installed blocking hook or
  1581. by the default blocking hook.  Thus, it is possible that the
  1582. application will cancel the DLL's blocking operation via
  1583. WSACancelBlockingCall().  If this occurs, the DLL's blocking operation
  1584. will fail with the error code WSAEINTR, and the DLL must return
  1585. control to the calling task as quickly as possible, as the used has
  1586. likely pressed a cancel or close button and the task has requested
  1587. control of the CPU.  It is recommended that DLLs which make blocking
  1588. calls install their own blocking hooks with WSASetBlockingHook() to
  1589. prevent unforeseen interactions between the application and the DLL.
  1590.  
  1591. Note that this is not necessary for DLLs in Windows NT because of its
  1592. different process and DLL structure.  Under Windows NT, the
  1593. intermediate DLL could simply call WSAStartup() in its DLL
  1594. initialization routine, which is called whenever a new process which
  1595. uses the DLL starts.
  1596.  
  1597. 3.3.6 Internal use of Messages by Windows Sockets Implementations
  1598. In order to implement Windows Sockets purely as a DLL, it may be
  1599. necessary for the DLL to post messages internally for communication
  1600. and timing.  This is perfectly legal; however, a Windows Sockets DLL
  1601. must not post messages to a window handle opened by a client
  1602. application except for those messages requested by the application.  A
  1603. Windows Sockets DLL that needs to use messages for its own purposes
  1604. must open a hidden window and post any necessary messages to the
  1605. handle for that window.
  1606.                                   23
  1607.  
  1608.  
  1609.  
  1610. 24 Socket Library Overview
  1611.  
  1612.  
  1613. 3.3.7 Private API Interfaces
  1614. The winsock.def file in Appendix B.7 lists the ordinals defined for
  1615. the Windows Sockets APIs.  In addition to the ordinal values listed,
  1616. all ordinals 999 and below are reserved for future Windows Sockets
  1617. use.  It may be convenient for a Windows Sockets implementation to
  1618. export additional, private interfaces from the Windows Sockets DLL.
  1619. This is perfectly acceptable, as long as the ordinals for these
  1620. exports are above 1000.  Note that any application that uses a
  1621. particular Windows Sockets DLL's private APIs will most likely not
  1622. work on any other vendor's Windows Sockets implementation.  Only the
  1623. APIs defined in this document are guaranteed to be present in every
  1624. Windows Sockets implementation.
  1625.  
  1626. If an application uses private interfaces of a particular vendor's
  1627. Windows Sockets DLL, it is recommended that the DLL not be statically
  1628. linked with the application but rather dynamically loaded with the
  1629. Windows routines LoadLibrary() and GetProcAddress().  This allows the
  1630. application to give an informative error message if it is run on a
  1631. system with a Windows Sockets DLL that does not support the same set
  1632. of extended functionality.
  1633.  
  1634.  
  1635.  
  1636.                                            Socket Library Reference 25
  1637.  
  1638.  
  1639. 4.  SOCKET LIBRARY REFERENCE
  1640.  
  1641. 4.1 Socket Routines
  1642. This chapter presents the socket library routines in alphabetical
  1643. order, and describes each routine in detail.
  1644.  
  1645. In each routine it is indicated that the header file winsock.h must be
  1646. included.  Appendix A.2 lists the Berkeley-compatible header files
  1647. which are supported.  These are provided for compatibility purposes
  1648. only, and each of them will simply include winsock.h.  The Windows
  1649. header file windows.h is also needed, but winsock.h will include it if
  1650. necessary.
  1651.  
  1652.  
  1653.  
  1654. 26 accept
  1655.  
  1656. 4.1.1 accept()
  1657. Description    Accept a connection on a socket.
  1658.  
  1659.           #include <winsock.h>
  1660.  
  1661.           SOCKET PASCAL FAR accept ( SOCKET s, struct sockaddr FAR *
  1662.           addr,
  1663.           int FAR * addrlen );
  1664.  
  1665.  
  1666.           s         A descriptor identifying a socket which is
  1667.                     listening for connections after a listen().
  1668.  
  1669.           addr      An optional pointer to a buffer which receives the
  1670.                     address of the connecting entity, as known to the
  1671.                     communications layer.  The exact format of the
  1672.                     addr argument is determined by the address family
  1673.                     established when the socket was created.
  1674.  
  1675.           addrlen   An optional pointer to an integer which contains
  1676.                     the length of the address addr.
  1677.  
  1678. Remarks   This routine extracts the first connection on the queue of
  1679.           pending connections on s, creates a new socket with the same
  1680.           properties as s and returns a handle to the new socket.  If
  1681.           no pending connections are present on the queue, and the
  1682.           socket is not marked as non-blocking, accept() blocks the
  1683.           caller until a connection is present.  If the socket is
  1684.           marked non-blocking and no pending connections are present
  1685.           on the queue, accept() returns an error as described below.
  1686.           The accepted socket may not be used to accept more
  1687.           connections.  The original socket remains open.
  1688.  
  1689.           The argument addr is a result parameter that is filled in
  1690.           with the address of the connecting entity, as known to the
  1691.           communications layer.  The exact format of the addr
  1692.           parameter is determined by the address family in which the
  1693.           communication is occurring.  The addrlen is a value-result
  1694.           parameter; it should initially contain the amount of space
  1695.           pointed to by addr; on return it will contain the actual
  1696.           length (in bytes) of the address returned.  This call is
  1697.           used with connection-based socket types such as SOCK_STREAM.
  1698.           If addr and/or addrlen are equal to NULL, then no
  1699.           information about the remote address of the accepted socket
  1700.           is returned.
  1701.  
  1702.  
  1703. Return Value   If no error occurs, accept() returns a value of type
  1704.           SOCKET which is a descriptor for the accepted packet.
  1705.           Otherwise, a value of INVALID_SOCKET is returned, and a
  1706.           specific error code may be retrieved by calling
  1707.           WSAGetLastError().
  1708.  
  1709.           The integer referred to by addrlen initially contains the
  1710.           amount of space pointed to by addr.  On return it will
  1711.           contain the actual length in bytes of the address returned.
  1712.  
  1713.  
  1714.  
  1715.                                                              accept 27
  1716.  
  1717. Error Codes                   WSANOTINITIALISED   A successful
  1718.                               WSAStartup() must occur before using
  1719.                               this API.
  1720.  
  1721.           WSAENETDOWN         The Windows Sockets implementation has
  1722.                               detected that the network subsystem has
  1723.                               failed.
  1724.  
  1725.           WSAEFAULT           The addrlen argument is too small (less
  1726.                               than the sizeof a struct sockaddr).
  1727.  
  1728.           WSAEINTR            The (blocking) call was canceled via
  1729.                               WSACancelBlockingCall().
  1730.  
  1731.           WSAEINPROGRESS      A blocking Windows Sockets call is in
  1732.                               progress.
  1733.  
  1734.           WSAEINVAL           listen() was not invoked prior to
  1735.                               accept().
  1736.  
  1737.           WSAEMFILE           The queue is empty upon entry to
  1738.                               accept() and there are no descriptors
  1739.                               available.
  1740.  
  1741.           WSAENOBUFS          No buffer space is available.
  1742.  
  1743.           WSAENOTSOCK         The descriptor is not a socket.
  1744.  
  1745.           WSAEOPNOTSUPP       The referenced socket is not a type that
  1746.                               supports connection-oriented service.
  1747.  
  1748.           WSAEWOULDBLOCK      The socket is marked as non-blocking and
  1749.                               no connections are present to be
  1750.                               accepted.
  1751.  
  1752. See Also  bind(), connect(), listen(), select(), socket(),
  1753.           WSAAsyncSelect()
  1754.  
  1755.  
  1756.  
  1757. 28 bind
  1758.  
  1759. 4.1.2 bind()
  1760. Description    Associate a local address with a socket.
  1761.  
  1762.           #include <winsock.h>
  1763.  
  1764.           int PASCAL FAR bind ( SOCKET s, const struct sockaddr FAR *
  1765.           name, int namelen );
  1766.  
  1767.  
  1768.           s         A descriptor identifying an unbound socket.
  1769.  
  1770.           name      The address to assign to the socket.  The sockaddr
  1771.                     structure is defined as follows:
  1772.  
  1773.                     struct sockaddr {
  1774.                          u_short   sa_family;
  1775.                          char sa_data[14];
  1776.                     };
  1777.  
  1778.           namelen   The length of the name.
  1779.  
  1780. Remarks   This routine is used on an unconnected datagram or stream
  1781.           socket, before subsequent connect()s or listen()s.  When a
  1782.           socket is created with socket(), it exists in a name space
  1783.           (address family), but it has no name assigned.  bind()
  1784.           establishes the local association (host address/port number)
  1785.           of the socket by assigning a local name to an unnamed
  1786.           socket.
  1787.  
  1788.           In the Internet address family, a name consists of several
  1789.           components.  For SOCK_DGRAM and SOCK_STREAM, the name
  1790.           consists of three parts: a host address, the protocol number
  1791.           (set implicitly to UDP or TCP, respectively), and a port
  1792.           number which identifies the application.  If an application
  1793.           does not care what address is assigned to it, it may specify
  1794.           an Internet address equal to INADDR_ANY, a port equal to 0,
  1795.           or both.  If the Internet address is equal to INADDR_ANY,
  1796.           any appropriate network interface will be used; this
  1797.           simplifies application programming in the presence of multi-
  1798.           homed hosts.  If the port is specified as 0, the Windows
  1799.           Sockets implementation will assign a unique port to the
  1800.           application with a value between 1024 and 5000.  The
  1801.           application may use getsockname() after bind() to learn the
  1802.           address that has been assigned to it, but note that
  1803.           getsockname() will not necessarily fill in the Internet
  1804.           address until the socket is connected, since several
  1805.           Internet addresses may be valid if the host is multi-homed.
  1806.  
  1807.           If an application desires to bind to an arbitrary port
  1808.           outside of the range 1024 to 5000, such as the case of rsh
  1809.           which must bind to any reserved port, code similar to the
  1810.           following may be used:
  1811.  
  1812.               SOCKADDR_IN sin;
  1813.               SOCKET s;
  1814.               u_short alport = IPPORT_RESERVED;
  1815.  
  1816.  
  1817.  
  1818.                                                                bind 29
  1819.  
  1820.               sin.sin_family = AF_INET;
  1821.               sin.sin_addr.s_addr = 0;
  1822.               for (;;) {
  1823.                   sin.sin_port = htons(alport);
  1824.                   if (bind(s, (LPSOCKADDR)&sin, sizeof (sin)) == 0) {
  1825.                       /* it worked */
  1826.                   }
  1827.                   if ( GetLastError() != WSAEADDRINUSE) {
  1828.                       /* fail */
  1829.                   }
  1830.                   alport--;
  1831.                   if (alport == IPPORT_RESERVED/2 ) {
  1832.                       /* fail--all unassigned reserved ports are */
  1833.                       /* in use. */
  1834.                   }
  1835.               }
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841. Return Value   If no error occurs, bind() returns 0.  Otherwise, it
  1842.           returns SOCKET_ERROR, and a specific error code may be
  1843.           retrieved by calling WSAGetLastError().
  1844.  
  1845. Error Codes                   WSANOTINITIALISED   A successful
  1846.                               WSAStartup() must occur before using
  1847.                               this API.
  1848.  
  1849.           WSAENETDOWN         The Windows Sockets implementation has
  1850.                               detected that the network subsystem has
  1851.                               failed.
  1852.  
  1853.           WSAEADDRINUSE       The specified address is already in use.
  1854.                               (See the SO_REUSEADDR socket option
  1855.                               under setsockopt().)
  1856.  
  1857.           WSAEFAULT           The namelen argument is too small (less
  1858.                               than the size of a struct sockaddr).
  1859.  
  1860.           WSAEINPROGRESS      A blocking Windows Sockets call is in
  1861.                               progress.
  1862.  
  1863.           WSAEAFNOSUPPORT     The specified address family is not
  1864.                               supported by this protocol.
  1865.  
  1866.           WSAEINVAL           The socket is already bound to an
  1867.                               address.
  1868.  
  1869.           WSAENOBUFS          Not enough buffers available, too many
  1870.                               connections.
  1871.  
  1872.           WSAENOTSOCK         The descriptor is not a socket.
  1873.  
  1874. See Also  connect(), listen(), getsockname(), setsockopt(), socket(),
  1875.           WSACancelBlockingCall().
  1876.  
  1877.  
  1878.  
  1879. 30 closesocket
  1880.  
  1881. 4.1.3 closesocket()
  1882. Description    Close a socket.
  1883.  
  1884.           #include <winsock.h>
  1885.  
  1886.           int PASCAL FAR closesocket ( SOCKET s );
  1887.  
  1888.  
  1889.           s         A descriptor identifying a socket.
  1890.  
  1891. Remarks   This function closes a socket.  More precisely, it releases
  1892.           the socket descriptor s, so that further references to s
  1893.           will fail with the error WSAENOTSOCK.  If this is the last
  1894.           reference to the underlying socket, the associated naming
  1895.           information and queued data are discarded.
  1896.  
  1897.           The semantics of closesocket() are affected by the socket
  1898.           options SO_LINGER and SO_DONTLINGER as follows:
  1899.  
  1900.           Option         Interval       Type of close  Wait for close?
  1901.           SO_DONTLINGER  Don't care     Graceful       No
  1902.           SO_LINGER      Zero      Hard      No
  1903.           SO_LINGER      Non-zero  Graceful       Yes
  1904.  
  1905.           If SO_LINGER is set (i.e. the l_onoff field of the linger
  1906.           structure is non-zero; see sections 2.4,  4.1.7 and 4.1.21)
  1907.           with a zero timeout interval (l_linger is zero),
  1908.           closesocket() is not blocked even if queued data has not yet
  1909.           been sent or acknowledged.  This is called a "hard" or
  1910.           "abortive" close, because the socket's virtual circuit is
  1911.           reset immediately, and any unsent data is lost.  Any recv()
  1912.           call on the remote side of the circuit will fail with
  1913.           WSAECONNRESET.
  1914.  
  1915.           If SO_LINGER is set with a non-zero timeout interval, the
  1916.           closesocket() call blocks until the remaining data has been
  1917.           sent or until the timeout expires.  This is called a
  1918.           graceful disconnect.  Note that if the socket is set to non-
  1919.           blocking and SO_LINGER is set to a non-zero timeout, the
  1920.           call to closesocket() will fail with an error of
  1921.           WSAEWOULDBLOCK.
  1922.  
  1923.           If SO_DONTLINGER is set on a stream socket (i.e. the l_onoff
  1924.           field of the linger structure is zero; see sections 2.4,
  1925.           4.1.7 and 4.1.21), the closesocket() call will return
  1926.           immediately.  However, any data queued for transmission will
  1927.           be sent if possible before the underlying socket is closed.
  1928.           This is also called a graceful disconnect.  Note that in
  1929.           this case the Windows Sockets implementation may not release
  1930.           the socket and other resources for an arbitrary period,
  1931.           which may affect applications which expect to use all
  1932.           available sockets.
  1933.  
  1934.  
  1935. Return Value   If no error occurs, closesocket() returns 0.
  1936.           Otherwise, a value of SOCKET_ERROR is returned, and a
  1937.  
  1938.  
  1939.  
  1940.                                                         closesocket 31
  1941.  
  1942.           specific error code may be retrieved by calling
  1943.           WSAGetLastError().
  1944.  
  1945. Error Codes                   WSANOTINITIALISED   A successful
  1946.                               WSAStartup() must occur before using
  1947.                               this API.
  1948.  
  1949.           WSAENETDOWN         The Windows Sockets implementation has
  1950.                               detected that the network subsystem has
  1951.                               failed.
  1952.  
  1953.           WSAENOTSOCK         The descriptor is not a socket.
  1954.  
  1955.           WSAEINPROGRESS      A blocking Windows Sockets call is in
  1956.                               progress.
  1957.  
  1958.           WSAEINTR            The (blocking) call was canceled via
  1959.                               WSACancelBlockingCall().
  1960.  
  1961.           WSAEWOULDBLOCK      The socket is marked as nonblocking and
  1962.                               SO_LINGER is set to a nonzero timeout
  1963.                               value.
  1964.  
  1965.  
  1966. See Also  accept(), socket(), ioctlsocket(), setsockopt(),
  1967.           WSAAsyncSelect().
  1968.  
  1969.  
  1970.  
  1971. 32 connect
  1972.  
  1973. 4.1.4 connect()
  1974. Description    Establish a connection to a peer.
  1975.  
  1976.           #include <winsock.h>
  1977.  
  1978.           int PASCAL FAR connect ( SOCKET s, const struct sockaddr FAR
  1979.           * name,
  1980.           int namelen );
  1981.  
  1982.  
  1983.           s         A descriptor identifying an unconnected socket.
  1984.  
  1985.           name      The name of the peer to which the socket is to be
  1986.                     connected.
  1987.  
  1988.           namelen   The length of the name.
  1989.  
  1990. Remarks   This function is used to create a connection to the
  1991.           specified foreign association.  The parameter s specifies an
  1992.           unconnected datagram or stream socket  If the socket is
  1993.           unbound, unique values are assigned to the local association
  1994.           by the system, and the socket is marked as bound.  Note that
  1995.           if the address field of the name structure is all zeroes,
  1996.           connect() will return the error WSAEADDRNOTAVAIL.
  1997.  
  1998.           For stream sockets (type SOCK_STREAM), an active connection
  1999.           is initiated to the foreign host using name (an address in
  2000.           the name space of the socket).  When the socket call
  2001.           completes successfully, the socket is ready to send/receive
  2002.           data.
  2003.  
  2004.           For a datagram socket (type SOCK_DGRAM), a default
  2005.           destination is set, which will be used on subsequent send()
  2006.           and recv() calls.
  2007.  
  2008.  
  2009. Return Value   If no error occurs, connect() returns 0.  Otherwise, it
  2010.           returns SOCKET_ERROR, and a specific error code may be
  2011.           retrieved by calling WSAGetLastError().
  2012.  
  2013.           On a blocking socket, the return value indicates success or
  2014.           failure of the connection attempt.
  2015.  
  2016.           On a non-blocking socket, if the return value is
  2017.           SOCKET_ERROR an application should call WSAGetLastError().
  2018.           If this indicates an error code of WSAEWOULDBLOCK, then your
  2019.           application can either:
  2020.  
  2021.           1. Use select() to determine the completion of the
  2022.           connection request by checking if the socket is writeable,
  2023.           or
  2024.  
  2025.           2. If your application is using the message-based
  2026.           WSAAsyncSelect() to indicate interest in connection events,
  2027.           then your application will receive an FD_CONNECT message
  2028.           when the connect operation is complete.
  2029.  
  2030.  
  2031.  
  2032.                                                             connect 33
  2033.  
  2034. Error Codes                   WSANOTINITIALISED   A successful
  2035.                               WSAStartup() must occur before using
  2036.                               this API.
  2037.  
  2038.           WSAENETDOWN         The Windows Sockets implementation has
  2039.                               detected that the network subsystem has
  2040.                               failed.
  2041.  
  2042.           WSAEADDRINUSE       The specified address is already in use.
  2043.  
  2044.           WSAEINTR            The (blocking) call was canceled via
  2045.                               WSACancelBlockingCall().
  2046.  
  2047.           WSAEINPROGRESS      A blocking Windows Sockets call is in
  2048.                               progress.
  2049.  
  2050.           WSAEADDRNOTAVAIL    The specified address is not available
  2051.                               from the local machine.
  2052.  
  2053.           WSAEAFNOSUPPORT     Addresses in the specified family cannot
  2054.                               be used with this socket.
  2055.  
  2056.           WSAECONNREFUSED     The attempt to connect was forcefully
  2057.                               rejected.
  2058.  
  2059.           WSAEDESTADDREQ      A destination address is required.
  2060.  
  2061.           WSAEFAULT           The namelen argument is incorrect.
  2062.  
  2063.           WSAEINVAL           The socket is not already bound to an
  2064.                               address.
  2065.  
  2066.           WSAEISCONN          The socket is already connected.
  2067.  
  2068.           WSAEMFILE           No more file descriptors are available.
  2069.  
  2070.           WSAENETUNREACH      The network can't be reached from this
  2071.                               host at this time.
  2072.  
  2073.           WSAENOBUFS          No buffer space is available.  The
  2074.                               socket cannot be connected.
  2075.  
  2076.           WSAENOTSOCK         The descriptor is not a socket.
  2077.  
  2078.           WSAETIMEDOUT        Attempt to connect timed out without
  2079.                               establishing a connection
  2080.  
  2081.           WSAEWOULDBLOCK      The socket is marked as non-blocking and
  2082.                               the connection cannot be completed
  2083.                               immediately.  It is possible to select()
  2084.                               the socket while it is connecting by
  2085.                               select()ing it for writing.
  2086.  
  2087. See Also  accept(), bind(), getsockname(), socket(), select() and
  2088.           WSAAsyncSelect()..
  2089.  
  2090.  
  2091.  
  2092. 34 getpeername
  2093.  
  2094. 4.1.5 getpeername()
  2095. Description    Get the address of the peer to which a socket is
  2096.           connected.
  2097.  
  2098.           #include <winsock.h>
  2099.  
  2100.           int PASCAL FAR getpeername ( SOCKET s, struct sockaddr FAR *
  2101.           name, int FAR * namelen );
  2102.  
  2103.  
  2104.           s         A descriptor identifying a connected socket.
  2105.  
  2106.           name      The structure which is to receive the name of the
  2107.                     peer.
  2108.  
  2109.           namelen   A pointer to the size of the name structure.
  2110.  
  2111. Remarks   getpeername() retrieves the name of the peer connected to
  2112.           the socket s and stores it in the struct sockaddr identified
  2113.           by name.  It is used on a connected datagram or stream
  2114.           socket.
  2115.  
  2116.           On return, the namelen argument contains the actual size of
  2117.           the name returned in bytes.
  2118.  
  2119.  
  2120. Return Value   If no error occurs, getpeername() returns 0.
  2121.           Otherwise, a value of SOCKET_ERROR is returned, and a
  2122.           specific error code may be retrieved by calling
  2123.           WSAGetLastError().
  2124.  
  2125. Error Codes                   WSANOTINITIALISED   A successful
  2126.                               WSAStartup() must occur before using
  2127.                               this API.
  2128.  
  2129.           WSAENETDOWN         The Windows Sockets implementation has
  2130.                               detected that the network subsystem has
  2131.                               failed.
  2132.  
  2133.           WSAEFAULT           The namelen argument is not large
  2134.                               enough.
  2135.  
  2136.           WSAEINPROGRESS      A blocking Windows Sockets call is in
  2137.                               progress.
  2138.  
  2139.           WSAENOTCONN         The socket is not connected.
  2140.  
  2141.           WSAENOTSOCK         The descriptor is not a socket.
  2142.  
  2143. See Also  bind(), socket(), getsockname().
  2144.  
  2145.  
  2146.  
  2147.                                                         getsockname 35
  2148.  
  2149. 4.1.6 getsockname()
  2150. Description    Get the local name for a socket.
  2151.  
  2152.           #include <winsock.h>
  2153.  
  2154.           int PASCAL FAR getsockname ( SOCKET s, struct sockaddr FAR *
  2155.           name,
  2156.           int FAR * namelen );
  2157.  
  2158.  
  2159.           s         A descriptor identifying a bound socket.
  2160.  
  2161.           name      Receives the address (name) of the socket.
  2162.  
  2163.           namelen    The size of the name buffer.
  2164.  
  2165. Remarks   getsockname() retrieves the current name for the specified
  2166.           socket descriptor in name.  It is used on a bound and/or
  2167.           connected socket specified by the s parameter.  The local
  2168.           association is returned.  This call is especially useful
  2169.           when a connect() call has been made without doing a bind()
  2170.           first; this call provides the only means by which you can
  2171.           determine the local association which has been set by the
  2172.           system.
  2173.  
  2174.           On return, the namelen argument contains the actual size of
  2175.           the name returned in bytes.
  2176.  
  2177.           If a socket was bound to INADDR_ANY, indicating that any of
  2178.           the host's IP addresses should be used for the socket,
  2179.           getsockname() will not necessarily return information about
  2180.           the host IP address, unless the socket has been connected
  2181.           with connect() or accept().  A Windows Sockets application
  2182.           must not assume that the IP address will be changed from
  2183.           INADDR_ANY unless the socket is connected.  This is because
  2184.           for a multi-homed host the IP address that will be used for
  2185.           the socket is unknown unless the socket is connected.
  2186.  
  2187. Return Value   If no error occurs, getsockname() returns 0.
  2188.           Otherwise, a value of SOCKET_ERROR is returned, and a
  2189.           specific error code may be retrieved by calling
  2190.           WSAGetLastError().
  2191.  
  2192. Error Codes                   WSANOTINITIALISED   A successful
  2193.                               WSAStartup() must occur before using
  2194.                               this API.
  2195.  
  2196.           WSAENETDOWN         The Windows Sockets implementation has
  2197.                               detected that the network subsystem has
  2198.                               failed.
  2199.  
  2200.           WSAEFAULT           The namelen argument is not large
  2201.                               enough.
  2202.  
  2203.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  2204.                               in progress.
  2205.  
  2206.  
  2207.  
  2208. 36 getsockname
  2209.  
  2210.           WSAENOTSOCK         The descriptor is not a socket.
  2211.  
  2212.           WSAEINVAL           The socket has not been bound to an
  2213.                               address with bind().
  2214.  
  2215. See Also  bind(), socket(), getpeername().
  2216.  
  2217.  
  2218.  
  2219.                                                          getsockopt 37
  2220.  
  2221. 4.1.7 getsockopt()
  2222. Description    Retrieve a socket option.
  2223.  
  2224.           #include <winsock.h>
  2225.  
  2226.               PASCAL FAR 
  2227.           int            getsockopt ( SOCKET s, int level, int
  2228.           optname,
  2229.           char FAR * optval, int FAR * optlen );
  2230.  
  2231.  
  2232.           s         A descriptor identifying a socket.
  2233.  
  2234.           level     The level at which the option is defined; the only
  2235.                     supported level  are 
  2236.                                      
  2237.                                    s     SOL_SOCKET and IPPROTO_TCP.
  2238.  
  2239.           optname   The socket option for which the value is to be
  2240.                     retrieved.
  2241.  
  2242.           optval    A pointer to the buffer in which the value for the
  2243.                     requested option is to be returned.
  2244.  
  2245.           optlen    A pointer to the size of the optval buffer.
  2246.  
  2247. Remarks   getsockopt() retrieves the current value for a socket option
  2248.           associated with a socket of any type, in any state, and
  2249.           stores the result in optval.  Options may exist at multiple
  2250.           protocol levels, but they are always present at the
  2251.           uppermost "socket'' level.  Options affect socket
  2252.           operations, such as whether an operation blocks or not, the
  2253.           routing of packets, out-of-band data transfer, etc.
  2254.  
  2255.           The value associated  with the selected option is returned
  2256.           in the buffer optval.  The integer pointed to by  optlen
  2257.           should originally contain the size of this buffer; on
  2258.           return, it will be set to the size of the value returned.
  2259.           For SO_LINGER, this will be the size of  a struct linger;
  2260.           for all other options it will be the size of an integer.
  2261.  
  2262.           If the option was never set with setsockopt(), then
  2263.           getsockopt() returns the default value for the option.
  2264.  
  2265.           The following options are supported for getsockopt().  The
  2266.           Type identifies the type of data addressed by optval.  The
  2267.           TCP_NODELAY option uses level IPPROTO_TCP; all other options
  2268.           use level SOL_SOCKET.
  2269.  
  2270.                Value        Type     Meaning
  2271.                SO_ACCEPTCO  BOOL     Socket is listen()ing.
  2272.                 N
  2273.                N
  2274.                SO_BROADCAS  BOOL     Socket is configured for the
  2275.                T                     transmission of broadcast
  2276.                                      messages.
  2277.                SO_DEBUG     BOOL     Debugging is enabled.
  2278.                SO_DONTLING  BOOL     If true, the SO_LINGER
  2279.                ER                    option is disabled.
  2280.                SO_DONTROUT  BOOL     Routing is disabled.
  2281.                E
  2282.  
  2283.  
  2284.  
  2285. 38 getsockopt
  2286.  
  2287.                SO_ERROR     int      Retrieve error status and
  2288.                                      clear.
  2289.                SO_KEEPALIV  BOOL     Keepalives are being sent.
  2290.                E
  2291.                SO_LINGER    struct   Returns the current linger
  2292.                             linger   options.
  2293.                             FAR *
  2294.                SO_OOBINLIN  BOOL     Out-of-band data is being
  2295.                E                     received in the normal data
  2296.                                      stream.
  2297.                SO_RCVBUF    int      Buffer size for receives
  2298.                SO_REUSEADD  BOOL     The socket may be bound to
  2299.                R                     an address which is already
  2300.                                      in use.
  2301.                SO_SNDBUF    int      Buffer size for sends
  2302.                SO_TYPE      int      The type of the socket (e.g.
  2303.                                      SOCK_STREAM).
  2304.                TCP_NODELAY  BOOL     Disables the Nagle algorithm
  2305.                                      for send coalescing.
  2306.  
  2307.                BSD options not supported for getsockopt() are:
  2308.  
  2309.                Value        Type     Meaning
  2310.                SO_RCVLOWAT  int      Receive low water mark
  2311.                SO_RCVTIMEO  int      Receive timeout
  2312.                SO_SNDLOWAT  int      Send low water mark
  2313.                SO_SNDTIMEO  int      Send timeout
  2314.                IP_OPTIONS            Get options in IP header.
  2315.                TCP_MAXSEG   int      Get TCP maximum segment
  2316.                                      size.
  2317.  
  2318.  
  2319.           Calling getsockopt() with an unsupported option will result
  2320.           in an error code of WSAENOPROTOOPT being returned from
  2321.           WSAGetLastError().
  2322.  
  2323.  
  2324.  
  2325. Return Value   If no error occurs, getsockopt() returns 0.  Otherwise,
  2326.           a value of SOCKET_ERROR is returned, and a specific error
  2327.           code may be retrieved by calling WSAGetLastError().
  2328.  
  2329. Error Codes                   WSANOTINITIALISED   A successful
  2330.                               WSAStartup() must occur before using
  2331.                               this API.
  2332.  
  2333.           WSAENETDOWN         The Windows Sockets implementation has
  2334.                               detected that the network subsystem has
  2335.                               failed.
  2336.  
  2337.           WSAEFAULT           The optlen argument was invalid.
  2338.  
  2339.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  2340.                               in progress.
  2341.  
  2342.  
  2343.  
  2344.                                                          getsockopt 39
  2345.  
  2346.           WSAENOPROTOOPT      The option is unknown or unsupported.
  2347.                               In particular, SO_BROADCAST is not
  2348.                               supported on sockets of type
  2349.                               SOCK_STREAM, while SO_ACCEPTCONN,
  2350.                               SO_DONTLINGER, SO_KEEPALIVE, SO_LINGER
  2351.                               and SO_OOBINLINE are not supported on
  2352.                               sockets of type SOCK_DGRAM.
  2353.  
  2354.           WSAENOTSOCK         The descriptor is not a socket.
  2355.  
  2356. See Also  setsockopt(), WSAAsyncSelect(), socket().
  2357.  
  2358.  
  2359.  
  2360. 40 htonl
  2361.  
  2362. 4.1.8 htonl()
  2363. Description    Convert a u_long from host to network byte order.
  2364.  
  2365.           #include <winsock.h>
  2366.  
  2367.           u_long PASCAL FAR htonl ( u_long hostlong );
  2368.  
  2369.  
  2370.           hostlong  A 32-bit number in host byte order.
  2371.  
  2372. Remarks   This routine takes a 32-bit number in host byte order and
  2373.           returns a 32-bit number in network byte order.
  2374.  
  2375.  
  2376. Return Value   htonl() returns the value in network byte order.
  2377.  
  2378. See Also  htons(), ntohl(), ntohs().
  2379.  
  2380.  
  2381.  
  2382.                                                               htons 41
  2383.  
  2384. 4.1.9 htons()
  2385. Description    Convert a u_short from host to network byte order.
  2386.  
  2387.           #include <winsock.h>
  2388.  
  2389.           u_short PASCAL FAR htons ( u_short hostshort );
  2390.  
  2391.  
  2392.           hostshort A 16-bit number in host byte order.
  2393.  
  2394. Remarks   This routine takes a 16-bit number in host byte order and
  2395.           returns a 16-bit number in network byte order.
  2396.  
  2397.  
  2398. Return Value   htons() returns the value in network byte order.
  2399.  
  2400. See Also  htonl(), ntohl(), ntohs().
  2401.  
  2402.  
  2403.  
  2404. 42 inet_addr
  2405.  
  2406. 4.1.10 inet_addr()
  2407. Description    Convert a string containing a dotted address into an
  2408.           in_addr.
  2409.  
  2410.           #include <winsock.h>
  2411.  
  2412.           unsigned long PASCAL FAR inet_addr ( const char FAR * cp );
  2413.  
  2414.  
  2415.           cp        A character string representing a number expressed
  2416.                     in the Internet standard ".'' notation.
  2417.  
  2418. Remarks   This function interprets the character string specified by
  2419.           the cp parameter.  This string represents a numeric Internet
  2420.           address expressed in the Internet standard ".'' notation.
  2421.           The value returned is a number suitable for use as an
  2422.           Internet address.  All Internet addresses are returned in
  2423.           network order (bytes ordered from left to right).
  2424.  
  2425.           Internet Addresses
  2426.  
  2427.           Values specified using the ".'' notation take one of the
  2428.           following forms:
  2429.  
  2430.           a.b.c.d   a.b.c     a.b  a
  2431.  
  2432.           When four parts are specified, each is interpreted as a byte
  2433.           of data and assigned, from left to right, to the four bytes
  2434.           of an Internet address.  Note that when an Internet address
  2435.           is viewed as a 32-bit integer quantity on the Intel
  2436.           architecture, the bytes referred to above appear as
  2437.           "d.c.b.a''.  That is, the bytes on an Intel processor are
  2438.           ordered from right to left.
  2439.  
  2440.           Note: The following notations are only used by Berkeley, and
  2441.           nowhere else on the Internet.  In the interests of
  2442.           compatibility with their software, they are supported as
  2443.           specified.
  2444.  
  2445.           When a three part address is specified, the last part is
  2446.           interpreted as a 16-bit quantity and placed in the right
  2447.           most two bytes of the network address.  This makes the three
  2448.           part address format convenient for specifying Class B
  2449.           network addresses as "128.net.host''.
  2450.  
  2451.           When a two part address is specified, the last part is
  2452.           interpreted as a 24-bit quantity and placed in the right
  2453.           most three bytes of the network address.  This makes the two
  2454.           part address format convenient for specifying Class A
  2455.           network addresses as "net.host''.
  2456.  
  2457.           When only one part is given, the value is stored directly in
  2458.           the network address without any byte rearrangement.
  2459.  
  2460.  
  2461. Return Value   If no error occurs, inet_addr() returns an unsigned
  2462.           long containing a suitable binary representation of the
  2463.  
  2464.  
  2465.  
  2466.                                                           inet_addr 43
  2467.  
  2468.           Internet address given.  If the passed-in string does not
  2469.           contain a legitimate Internet address, for example if a
  2470.           portion of an "a.b.c.d" address exceeds 255, inet_addr()
  2471.           returns the value INADDR_NONE.
  2472.  
  2473. See Also  inet_ntoa()
  2474.  
  2475.  
  2476.  
  2477. 44 inet_ntoa
  2478.  
  2479. 4.1.11 inet_ntoa()
  2480. Description    Convert a network address into a string in dotted
  2481.           format.
  2482.  
  2483.           #include <winsock.h>
  2484.  
  2485.           char FAR * PASCAL FAR inet_ntoa ( struct in_addr in );
  2486.  
  2487.  
  2488.           in        A structure which represents an Internet host
  2489.                     address.
  2490.  
  2491. Remarks   This function takes an Internet address structure specified
  2492.           by the in parameter.  It returns an ASCII string
  2493.           representing the address in ".''  notation as "a.b.c.d''.
  2494.           Note that the string returned by inet_ntoa() resides in
  2495.           memory which is allocated by the Windows Sockets
  2496.           implementation.  The application should not make any
  2497.           assumptions about the way in which the memory is allocated.
  2498.           The data is guaranteed to be valid until the next Windows
  2499.           Sockets API call within the same thread, but no longer.
  2500.  
  2501.  
  2502. Return Value   If no error occurs, inet_ntoa() returns a char pointer
  2503.           to a static buffer containing the text address in standard
  2504.           ".'' notation.  Otherwise, it returns NULL.  The data should
  2505.           be copied before another Windows Sockets call is made.
  2506.  
  2507. See Also  inet_addr().
  2508.  
  2509.  
  2510.  
  2511.                                                         ioctlsocket 45
  2512.  
  2513. 4.1.12 ioctlsocket()
  2514. Description    Control the mode of a socket.
  2515.  
  2516.           #include <winsock.h>
  2517.  
  2518.           int PASCAL FAR ioctlsocket ( SOCKET s, long cmd, u_long FAR
  2519.           * argp );
  2520.  
  2521.  
  2522.           s         A descriptor identifying a socket.
  2523.  
  2524.           cmd       The command to perform on the socket s.
  2525.  
  2526.           argp      A pointer to a parameter for cmd.
  2527.  
  2528. Remarks   This routine may be used on any socket in any state.  It is
  2529.           used to get or retrieve operating parameters associated with
  2530.           the socket, independent of the protocol and communications
  2531.           subsystem.  The following commands are supported:
  2532.  
  2533.           Command   Semantics
  2534.  
  2535.           FIONBIO   Enable or disable non-blocking mode on the socket
  2536.                     s.  argp points at an unsigned long, which is non-
  2537.                     zero if non-blocking mode is to be enabled and
  2538.                     zero if it is to be disabled.  When a socket is
  2539.                     created, it operates in blocking mode (i.e. non-
  2540.                     blocking mode is disabled).  This is consistent
  2541.                     with BSD sockets.
  2542.  
  2543.                     The WSAAsyncSelect() routine automatically sets a
  2544.                     socket to nonblocking mode.  If WSAAsyncSelect()
  2545.                     has been issued on a socket, then any attempt to
  2546.                     use ioctlsocket() to set the socket back to
  2547.                     blocking mode will fail with WSAEINVAL.  To set
  2548.                     the socket back to blocking mode, an application
  2549.                     must first disable WSAAsyncSelect() by calling
  2550.                     WSAAsyncSelect() with the lEvent parameter equal
  2551.                     to 0.
  2552.  
  2553.           FIONREAD  Determine the amount of data which can be read
  2554.                     atomically from socket s.  argp points at an
  2555.                     unsigned long in which ioctlsocket() stores the
  2556.                     result.  If s is of type SOCK_STREAM, FIONREAD
  2557.                     returns the total amount of data which may be read
  2558.                     in a single recv(); this is normally the same as
  2559.                     the total amount of data queued on the socket.  If
  2560.                     s is of type SOCK_DGRAM, FIONREAD returns the size
  2561.                     of the first datagram queued on the socket.
  2562.  
  2563.           SIOCATMARK     Determine whether or not all out-of-band data
  2564.                     has been read.  This applies only to a socket of
  2565.                     type SOCK_STREAM which has been configured for in-
  2566.                     line reception of any out-of-band data
  2567.                     (SO_OOBINLINE).  If no out-of-band data is waiting
  2568.                     to be read,  the operation returns TRUE.
  2569.                     Otherwise it returns FALSE, and the next recv() or
  2570.  
  2571.  
  2572.  
  2573. 46 ioctlsocket
  2574.  
  2575.                     recvfrom() performed on the socket will retrieve
  2576.                     some or all of the data preceding the "mark"; the
  2577.                     application should use the SIOCATMARK operation to
  2578.                     determine whether any remains.  If there is any
  2579.                     normal data preceding the "urgent" (out of band)
  2580.                     data, it will be received in order.  (Note that a
  2581.                     recv() or recvfrom() will never mix out-of-band
  2582.                     and normal data in the same call.)  argp points at
  2583.                     a BOOL in which ioctlsocket() stores the result.
  2584.  
  2585. Compatibility  This function is a subset of ioctl() as used in
  2586.           Berkeley sockets.  In particular, there is no command which
  2587.           is equivalent to FIOASYNC, while SIOCATMARK is the only
  2588.           socket-level command which is supported.
  2589.  
  2590.  
  2591. Return Value   Upon successful completion, the ioctlsocket() returns
  2592.           0.  Otherwise, a value of SOCKET_ERROR is returned, and a
  2593.           specific error code may be retrieved by calling
  2594.           WSAGetLastError().
  2595.  
  2596. Error Codes                   WSANOTINITIALISED   A successful
  2597.                               WSAStartup() must occur before using
  2598.                               this API.
  2599.  
  2600.           WSAENETDOWN         The Windows Sockets implementation has
  2601.                               detected that the network subsystem has
  2602.                               failed.
  2603.  
  2604.           WSAEINVAL           cmd is not a valid command, or argp is
  2605.                               not an acceptable parameter for cmd, or
  2606.                               the command is not applicable to the
  2607.                               type of socket supplied
  2608.  
  2609.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  2610.                               in progress.
  2611.  
  2612.           WSAENOTSOCK         The descriptor s is not a socket.
  2613.  
  2614.  
  2615. See Also  socket(), setsockopt(), getsockopt(), WSAAsyncSelect().
  2616.  
  2617.  
  2618.  
  2619.                                                              listen 47
  2620.  
  2621. 4.1.13 listen()
  2622. Description    Establish a socket to listen for incoming connection.
  2623.  
  2624.           #include <winsock.h>
  2625.  
  2626.           int PASCAL FAR listen ( SOCKET s, int backlog );
  2627.  
  2628.           s         A descriptor identifying a bound, unconnected
  2629.                     socket.
  2630.  
  2631.           backlog   The maximum length to which the queue of pending
  2632.                     connections may grow.
  2633.  
  2634. Remarks   To accept connections, a socket is first created with
  2635.           socket(), a backlog for incoming connections is specified
  2636.           with listen(), and then the connections are accepted with
  2637.           accept().  listen() applies only to sockets that support
  2638.           connections, i.e. those of type SOCK_STREAM.  The socket s
  2639.           is put into "passive'' mode where incoming connections are
  2640.           acknowledged and queued pending acceptance by the process.
  2641.  
  2642.           This function is typically used by servers that could have
  2643.           more than one connection request at a time: if a connection
  2644.           request arrives with the queue full, the client will receive
  2645.           an error with an indication of WSAECONNREFUSED.
  2646.  
  2647.           listen() attempts to continue to function rationally when
  2648.           there are no available descriptors.  It will accept
  2649.           connections until the queue is emptied.  If descriptors
  2650.           become available, a later call to listen() or accept() will
  2651.           re-fill the queue to the current or most recent "backlog'',
  2652.           if possible, and resume listening for incoming connections.
  2653.  
  2654. Compatibility  backlog is currently limited (silently) to 5.  As in
  2655.           4.3BSD, illegal values (less than 1 or greater than 5) are
  2656.           replaced by the nearest legal value.
  2657.  
  2658. Return Value   If no error occurs, listen() returns 0.  Otherwise, a
  2659.           value of SOCKET_ERROR is returned, and a specific error code
  2660.           may be retrieved by calling WSAGetLastError().
  2661.  
  2662. Error Codes                   WSANOTINITIALISED   A successful
  2663.                               WSAStartup() must occur before using
  2664.                               this API.
  2665.  
  2666.           WSAENETDOWN         The Windows Sockets implementation has
  2667.                               detected that the network subsystem has
  2668.                               failed.
  2669.  
  2670.           WSAEADDRINUSE       An attempt has been made to listen() on
  2671.                               an address in use.
  2672.  
  2673.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  2674.                               in progress.
  2675.  
  2676.           WSAEINVAL           The socket has not been bound with
  2677.                               bind() or is already connected.
  2678.  
  2679.  
  2680.  
  2681. 48 listen
  2682.  
  2683.  
  2684.           WSAEISCONN          The socket is already connected.
  2685.  
  2686.           WSAEMFILE           No more file descriptors are available.
  2687.  
  2688.           WSAENOBUFS          No buffer space is available.
  2689.  
  2690.           WSAENOTSOCK         The descriptor is not a socket.
  2691.  
  2692.           WSAEOPNOTSUPP       The referenced socket is not of a type
  2693.                               that supports the listen() operation.
  2694.  
  2695. See Also  accept(),  connect(), socket().
  2696.  
  2697.  
  2698.  
  2699.                                                               ntohl 49
  2700.  
  2701. 4.1.14 ntohl()
  2702. Description    Convert a u_long from network to host byte order.
  2703.  
  2704.           #include <winsock.h>
  2705.  
  2706.           u_long PASCAL FAR ntohl ( u_long netlong );
  2707.  
  2708.  
  2709.           netlong   A 32-bit number in network byte order.
  2710.  
  2711. Remarks   This routine takes a 32-bit number in network byte order and
  2712.           returns a 32-bit number in host byte order.
  2713.  
  2714.  
  2715. Return Value   ntohl() returns the value in host byte order.
  2716.  
  2717. See Also  htonl(), htons(), ntohs().
  2718.  
  2719.  
  2720.  
  2721. 50 ntohs
  2722.  
  2723. 4.1.15 ntohs()
  2724. Description    Convert a u_short from network to host byte order.
  2725.  
  2726.           #include <winsock.h>
  2727.  
  2728.           u_short PASCAL FAR ntohs ( u_short netshort );
  2729.  
  2730.  
  2731.           netshort  A 16-bit number in network byte order.
  2732.  
  2733. Remarks   This routine takes a 16-bit number in network byte order and
  2734.           returns a 16-bit number in host byte order.
  2735.  
  2736.  
  2737. Return Value   ntohs() returns the value in host byte order.
  2738.  
  2739. See Also  htonl(), htons(), ntohl().
  2740.  
  2741.  
  2742.  
  2743.                                                                recv 51
  2744.  
  2745. 4.1.16 recv()
  2746. Description    Receive data from a socket.
  2747.  
  2748.           #include <winsock.h>
  2749.  
  2750.           int PASCAL FAR recv ( SOCKET s, char FAR * buf, int len, int
  2751.           flags );
  2752.  
  2753.  
  2754.           s         A descriptor identifying a connected socket.
  2755.  
  2756.           buf       A buffer for the incoming data.
  2757.  
  2758.           len       The length of buf.
  2759.  
  2760.           flags     Specifies the way in which the call is made.
  2761.  
  2762. Remarks   This function is used on connected datagram or stream
  2763.           sockets specified by the s parameter and is used to read
  2764.           incoming data.
  2765.  
  2766.           For sockets of type SOCK_STREAM, as much information as is
  2767.           currently available up to the size of the buffer supplied is
  2768.           returned.  If the socket has been configured for in-line
  2769.           reception of out-of-band data (socket option SO_OOBINLINE)
  2770.           and out-of-band data is unread, only out-of-band data will
  2771.           be returned.  The application may use the ioctlsocket()
  2772.           SIOCATMARK to determine whether any more out-of-band data
  2773.           remains to be read.
  2774.  
  2775.           For datagram sockets, data is extracted from the first
  2776.           enqueued datagram, up to the size of the buffer supplied.
  2777.           If the datagram is larger than the buffer supplied, the
  2778.           buffer is filled with the first part of the datagram, the
  2779.           excess data is lost, and recv() returns the error
  2780.           WSAEMSGSIZE.
  2781.  
  2782.           If no incoming data is available at the socket, the recv()
  2783.           call waits for data to arrive unless the socket is non-
  2784.           blocking.  In this case a value of SOCKET_ERROR is returned
  2785.           with the error code set to WSAEWOULDBLOCK.  The select() or
  2786.           WSAAsyncSelect() calls may be used to determine when more
  2787.           data arrives.
  2788.  
  2789.           If the socket is of type SOCK_STREAM and the remote side has
  2790.           shut down the connection gracefully, a recv() will complete
  2791.           immediately with 0 bytes received.  If the connection has
  2792.           been reset, a recv() will fail with the error WSAECONNRESET.
  2793.  
  2794.           Flags may be used to influence the behavior of the function
  2795.           invocation beyond the options specified for the associated
  2796.           socket.  That is, the semantics of this function are
  2797.           determined by the socket options and the flags parameter.
  2798.           The latter is constructed by or-ing any of the following
  2799.           values:
  2800.  
  2801.           Value     Meaning
  2802.  
  2803.  
  2804.  
  2805. 52 recv
  2806.  
  2807.           MSG_PEEK  Peek at the incoming data.  The data is copied
  2808.                     into the buffer but is not removed from the input
  2809.                     queue.
  2810.  
  2811.           MSG_OOB   Process out-of-band data (See section 2.2.3 for a
  2812.                     discussion of this topic.)
  2813.  
  2814.  
  2815.  
  2816. Return Value   If no error occurs, recv() returns the number of bytes
  2817.           received.  If the connection has been closed, it returns 0.
  2818.           Otherwise, a value of SOCKET_ERROR is returned, and a
  2819.           specific error code may be retrieved by calling
  2820.           WSAGetLastError().
  2821.  
  2822. Error Codes                   WSANOTINITIALISED   A successful
  2823.                               WSAStartup() must occur before using
  2824.                               this API.
  2825.  
  2826.           WSAENETDOWN         The Windows Sockets implementation has
  2827.                               detected that the network subsystem has
  2828.                               failed.
  2829.  
  2830.           WSAENOTCONN         The socket is not connected.
  2831.  
  2832.           WSAEINTR            The (blocking) call was canceled via
  2833.                               WSACancelBlockingCall().
  2834.  
  2835.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  2836.                               in progress.
  2837.  
  2838.           WSAENOTSOCK         The descriptor is not a socket.
  2839.  
  2840.           WSAEOPNOTSUPP       MSG_OOB was specified, but the socket is
  2841.                               not of type SOCK_STREAM.
  2842.  
  2843.           WSAESHUTDOWN        The socket has been shutdown; it is not
  2844.                               possible to recv() on a socket after
  2845.                               shutdown() has been invoked with how set
  2846.                               to 0 or 2.
  2847.  
  2848.           WSAEWOULDBLOCK      The socket is marked as non-blocking and
  2849.                               the receive operation would block.
  2850.  
  2851.           WSAEMSGSIZE         The datagram was too large to fit into
  2852.                               the specified buffer and was truncated.
  2853.  
  2854.           WSAEINVAL           The socket has not been bound with
  2855.                               bind().
  2856.  
  2857.           WSAECONNABORTED     The virtual circuit was aborted due to
  2858.                               timeout or other failure.
  2859.  
  2860.           WSAECONNRESET       The virtual circuit was reset by the
  2861.                               remote side.
  2862.  
  2863.  
  2864.  
  2865.                                                                recv 53
  2866.  
  2867. See Also  recvfrom(), read(), ,recv(), send(), select(),
  2868.           WSAAsyncSelect(), socket()
  2869.  
  2870.  
  2871.  
  2872. 54 recvfrom
  2873.  
  2874. 4.1.17 recvfrom()
  2875. Description    Receive a datagram and store the source address.
  2876.  
  2877.           #include <winsock.h>
  2878.  
  2879.           int PASCAL FAR recvfrom ( SOCKET s, char FAR * buf, int len,
  2880.           int flags,
  2881.           struct sockaddr FAR * from, int FAR * fromlen );
  2882.  
  2883.  
  2884.           s         A descriptor identifying a bound socket.
  2885.  
  2886.           buf       A buffer for the incoming data.
  2887.  
  2888.           len       The length of buf.
  2889.  
  2890.           flags     Specifies the way in which the call is made.
  2891.  
  2892.           from      An optional pointer to a buffer which will hold
  2893.                     the source address upon return.
  2894.  
  2895.           fromlen   An optional pointer to the size of the from
  2896.                     buffer.
  2897.  
  2898. Remarks   This function is used to read incoming data on a (possibly
  2899.           connected) socket and capture the address from which the
  2900.           data was sent.
  2901.  
  2902.           For sockets of type SOCK_STREAM, as much information as is
  2903.           currently available up to the size of the buffer supplied is
  2904.           returned.  If the socket has been configured for in-line
  2905.           reception of out-of-band data (socket option SO_OOBINLINE)
  2906.           and out-of-band data is unread, only out-of-band data will
  2907.           be returned.  The application may use the ioctlsocket()
  2908.           SIOCATMARK to determine whether any more out-of-band data
  2909.           remains to be read.  The from and fromlen parameters are
  2910.           ignored for SOCK_STREAM sockets.
  2911.  
  2912.           For datagram sockets, data is extracted from the first
  2913.           enqueued datagram, up to the size of the buffer supplied.
  2914.           If the datagram is larger than the buffer supplied, the
  2915.           buffer is filled with the first part of the message, the
  2916.           excess data is lost, and recvfrom() returns the error code
  2917.           WSAEMSGSIZE.
  2918.  
  2919.           If from is non-zero, and the socket is of type SOCK_DGRAM,
  2920.           the network address of the peer which sent the data is
  2921.           copied to the corresponding struct sockaddr.  The value
  2922.           pointed to by fromlen is initialized to the size of this
  2923.           structure, and is modified on return to indicate the actual
  2924.           size of the address stored there.
  2925.  
  2926.           If no incoming data is available at the socket, the
  2927.           recvfrom() call waits for data to arrive unless the socket
  2928.           is non-blocking.  In this case a value of SOCKET_ERROR is
  2929.           returned with the error code set to WSAEWOULDBLOCK.  The
  2930.  
  2931.  
  2932.  
  2933.                                                            recvfrom 55
  2934.  
  2935.           select() or WSAAsyncSelect() calls may be used to determine
  2936.           when more data arrives.
  2937.  
  2938.           If the socket is of type SOCK_STREAM and the remote side has
  2939.           shut down the connection gracefully, a recvfrom() will
  2940.           complete immediately with 0 bytes received.  If the
  2941.           connection has been reset recv() will fail with the error
  2942.           WSAECONNRESET.
  2943.  
  2944.           Flags may be used to influence the behavior of the function
  2945.           invocation beyond the options specified for the associated
  2946.           socket.  That is, the semantics of this function are
  2947.           determined by the socket options and the flags parameter.
  2948.           The latter is constructed by or-ing any of the following
  2949.           values:
  2950.  
  2951.           Value     Meaning
  2952.           MSG_PEEK  Peek at the incoming data.  The data is copied
  2953.                     into the buffer but is not removed from the input
  2954.                     queue.
  2955.  
  2956.           MSG_OOB   Process out-of-band data (See section 2.2.3 for a
  2957.                     discussion of this topic.)
  2958.  
  2959.  
  2960.  
  2961. Return Value   If no error occurs, recvfrom() returns the number of
  2962.           bytes received.  If the connection has been closed, it
  2963.           returns 0.  Otherwise, a value of SOCKET_ERROR is returned,
  2964.           and a specific error code may be retrieved by calling
  2965.           WSAGetLastError().
  2966.  
  2967. Error Codes                   WSANOTINITIALISED   A successful
  2968.                               WSAStartup() must occur before using
  2969.                               this API.
  2970.  
  2971.           WSAENETDOWN         The Windows Sockets implementation has
  2972.                               detected that the network subsystem has
  2973.                               failed.
  2974.  
  2975.           WSAEFAULT           The fromlen argument was invalid: the
  2976.                               from buffer was too small to accommodate
  2977.                               the peer address.
  2978.  
  2979.           WSAEINTR            The (blocking) call was canceled via
  2980.                               WSACancelBlockingCall().
  2981.  
  2982.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  2983.                               in progress.
  2984.  
  2985.           WSAEINVAL           The socket has not been bound with
  2986.                               bind().
  2987.  
  2988.           WSAENOTCONN         The socket is not connected (SOCK_STREAM
  2989.                               only).
  2990.  
  2991.           WSAENOTSOCK         The descriptor is not a socket.
  2992.  
  2993.  
  2994.  
  2995. 56 recvfrom
  2996.  
  2997.  
  2998.           WSAEOPNOTSUPP       MSG_OOB was specified, but the socket is
  2999.                               not of type SOCK_STREAM.
  3000.  
  3001.           WSAESHUTDOWN        The socket has been shutdown; it is not
  3002.                               possible to recvfrom() on a socket after
  3003.                               shutdown() has been invoked with how set
  3004.                               to 0 or 2.
  3005.  
  3006.           WSAEWOULDBLOCK      The socket is marked as non-blocking and
  3007.                               the recvfrom() operation would block.
  3008.  
  3009.           WSAEMSGSIZE         The datagram was too large to fit into
  3010.                               the specified buffer and was truncated.
  3011.  
  3012.           WSAECONNABORTED     The virtual circuit was aborted due to
  3013.                               timeout or other failure.
  3014.  
  3015.           WSAECONNRESET       The virtual circuit was reset by the
  3016.                               remote side.
  3017.  
  3018.  
  3019. See Also  recv(), send(), socket(), WSAAsyncSelect().
  3020.  
  3021.  
  3022.  
  3023.                                                              select 57
  3024.  
  3025. 4.1.18 select()
  3026. Description    Determine the status of one or more sockets, waiting if
  3027.           necessary.
  3028.  
  3029.           #include <winsock.h>
  3030.  
  3031.           int PASCAL FAR select ( int nfds, fd_set FAR * readfds,
  3032.           fd_set FAR * writefds,
  3033.           fd_set FAR * exceptfds, const struct timeval FAR * timeout
  3034.           );
  3035.  
  3036.  
  3037.           nfds      This argument is ignored and included only for the
  3038.                     sake of compatibility.
  3039.  
  3040.           readfds   An optional pointer to a set of sockets to be
  3041.                     checked for readability.
  3042.  
  3043.           writefds  An optional pointer to a set of sockets to be
  3044.                     checked for writability
  3045.  
  3046.           exceptfds An optional pointer to a set of sockets to be
  3047.                     checked for errors.
  3048.  
  3049.           timeout   The maximum time for select() to wait, or NULL for
  3050.                     blocking operation.
  3051.  
  3052. Remarks   This function is used to determine the status of one or more
  3053.           sockets.  For each socket, the caller may request
  3054.           information on read, write or error status.  The set of
  3055.           sockets for which a given status is requested is indicated
  3056.           by an fd_set structure.  Upon return, the structure is
  3057.           updated to reflect the subset of these sockets which meet
  3058.           the specified condition, and select() returns the number of
  3059.           sockets meeting the conditions.  A set of macros is provided
  3060.           for manipulating an fd_set.  These macros are compatible
  3061.           with those used in the Berkeley software, but the underlying
  3062.           representation is completely different.
  3063.  
  3064.           The parameter readfds identifies those sockets which are to
  3065.           be checked for readability.  If the socket is currently
  3066.           listen()ing, it will be marked as readable if an incoming
  3067.           connection request has been received, so that an accept() is
  3068.           guaranteed to complete without blocking.  For other sockets,
  3069.           readability means that queued data is available for reading
  3070.           or, for sockets of type SOCK_STREAM, that the virtual socket
  3071.           corresponding to the socket has been closed, so that a
  3072.           recv() or recvfrom() is guaranteed to complete without
  3073.           blocking.  If the virtual circuit was closed gracefully,
  3074.           then a recv() will return immediately with 0 bytes read; if
  3075.           the virtual circuit was reset, then a recv() will complete
  3076.           immediately with the error code WSAECONNRESET. The presence
  3077.           of out-of-band data will be checked if the socket option
  3078.           SO_OOBINLINE has been enabled (see setsockopt()).
  3079.  
  3080.           The parameter writefds identifies those sockets which are to
  3081.           be checked for writability.   If a socket is connect()ing
  3082.  
  3083.  
  3084.  
  3085. 58 select
  3086.  
  3087.           (non-blocking), writability means that the connection
  3088.           establishment successfully completed.  If the socket is not
  3089.           in the process of connect()ing, writability means that a
  3090.           send() or sendto() will complete without blocking.  [It is
  3091.           not specified how long this guarantee can be assumed to be
  3092.           valid, particularly in a multithreaded environment.]
  3093.  
  3094.           The parameter exceptfds identifies those sockets which are
  3095.           to be checked for the presence of out-of-band data or any
  3096.           exceptional error conditions.  Note that out-of-band data
  3097.           will only be reported in this way if the option SO_OOBINLINE
  3098.           is FALSE.  For a SOCK_STREAM, the breaking of the connection
  3099.           by the peer or due to KEEPALIVE failure will be indicated as
  3100.           an exception.  This specification does not define which
  3101.           other errors will be included.  If a socket is connect()ing
  3102.           (non-blocking), failure of the connect attempt is indicated
  3103.           in exceptfds.
  3104.  
  3105.           Any of readfds, writefds, or exceptfds may be given as NULL
  3106.           if no descriptors are of interest.
  3107.  
  3108.           Four macros are defined in the header file winsock.h for
  3109.           manipulating the descriptor sets.  The variable FD_SETSIZE
  3110.           determines the maximum number of descriptors in a set.  (The
  3111.           default value of FD_SETSIZE is 64, which may be modified by
  3112.           #defining FD_SETSIZE to another value before #including
  3113.           winsock.h.)  Internally, an fd_set is represented as an
  3114.           array of SOCKETs; the last valid entry is followed by an
  3115.           element set to INVALID_SOCKET.  The macros are:
  3116.  
  3117.           FD_CLR(s, *set)     Removes the descriptor s from set.
  3118.  
  3119.           FD_ISSET(s, *set)   Nonzero if s is a member of the set,
  3120.                     zero otherwise.
  3121.  
  3122.           FD_SET(s, *set)          Adds descriptor s to set.
  3123.  
  3124.           FD_ZERO(*set)       Initializes the set to the NULL set.
  3125.  
  3126.           The parameter timeout controls how long the select() may
  3127.           take to complete.  If timeout is a null pointer, select()
  3128.           will block indefinitely until at least one descriptor meets
  3129.           the specified criteria.  Otherwise, timeout points to a
  3130.           struct timeval which specifies the maximum time that
  3131.           select() should wait before returning.  If the timeval is
  3132.           initialized to {0, 0}, select() will return immediately;
  3133.           this is used to "poll" the state of the selected sockets.
  3134.           If this is the case, then the select() call is considered
  3135.           nonblocking and the standard assumptions for nonblocking
  3136.           calls apply.  For example, the blocking hook must not be
  3137.           called, and the Windows Sockets implementation must not
  3138.           yield.
  3139.  
  3140. Return Value   select() returns the total number of descriptors which
  3141.           are ready and contained in the fd_set structures, 0 if the
  3142.           time limit expired, or SOCKET_ERROR if an error occurred.
  3143.  
  3144.  
  3145.  
  3146.                                                              select 59
  3147.  
  3148.           If the return value is SOCKET_ERROR, WSAGetLastError() may
  3149.           be used to retrieve a specific error code.
  3150.  
  3151. Error Codes                   WSANOTINITIALISED   A successful
  3152.                               WSAStartup() must occur before using
  3153.                               this API.
  3154.  
  3155.           WSAENETDOWN         The Windows Sockets implementation has
  3156.                               detected that the network subsystem has
  3157.                               failed.
  3158.  
  3159.           WSAEINVAL           The timeout value is not valid.
  3160.  
  3161.           WSAEINTR            The (blocking) call was canceled via
  3162.                               WSACancelBlockingCall().
  3163.  
  3164.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  3165.                               in progress.
  3166.  
  3167.           WSAENOTSOCK         One of the descriptor sets contains an
  3168.                               entry which is not a socket.
  3169.  
  3170. See Also  WSAAsyncSelect(), accept(), connect(), recv(), recvfrom(),
  3171.           send().
  3172.  
  3173.  
  3174.  
  3175. 60 send
  3176.  
  3177. 4.1.19 send()
  3178. Description    Send data on a connected socket.
  3179.  
  3180.           #include <winsock.h>
  3181.  
  3182.           int PASCAL FAR send ( SOCKET s, const char FAR * buf, int
  3183.           len, int flags );
  3184.  
  3185.  
  3186.           s         A descriptor identifying a connected socket.
  3187.  
  3188.           buf       A buffer containing the data to be transmitted.
  3189.  
  3190.           len       The length of the data in buf.
  3191.  
  3192.           flags     Specifies the way in which the call is made.
  3193.  
  3194. Remarks   send() is used on connected datagram or stream sockets and
  3195.           is used to write outgoing data on a socket.  For datagram
  3196.           sockets, care must be taken not to exceed the maximum IP
  3197.           packet size of the underlying subnets, which is given by the
  3198.           iMaxUdpDg element in the WSAData structure returned by
  3199.           WSAStartup().  If the data is too long to pass atomically
  3200.           through the underlying protocol the error WSAEMSGSIZE is
  3201.           returned, and no data is transmitted.
  3202.  
  3203.           Note that the successful completion of a send() does not
  3204.           indicate that the data was successfully delivered.
  3205.  
  3206.           If no buffer space is available within the transport system
  3207.           to hold the data to be transmitted, send() will block unless
  3208.           the socket has been placed in a non-blocking I/O mode.  On
  3209.           non-blocking SOCK_STREAM sockets, the number of bytes
  3210.           written may be between 1 and the requested length, depending
  3211.           on buffer availability on both the local and foreign hosts.
  3212.           The select() call may be used to determine when it is
  3213.           possible to send more data.
  3214.  
  3215.           Flags may be used to influence the behavior of the function
  3216.           invocation beyond the options specified for the associated
  3217.           socket.  That is, the semantics of this function are
  3218.           determined by the socket options and the flags parameter.
  3219.           The latter is constructed by or-ing any of the following
  3220.           values:
  3221.  
  3222.           Value     Meaning
  3223.           MSG_DONTROUTE
  3224.                     Specifies that the data should not be subject to
  3225.                     routing.  A Windows Sockets supplier may choose to
  3226.                     ignore this flag; see also the discussion of the
  3227.                     SO_DONTROUTE option in section 2.4.
  3228.  
  3229.           MSG_OOB   Send out-of-band data (SOCK_STREAM only; see also
  3230.                     section 2.2.3)
  3231.  
  3232.  
  3233.  
  3234.                                                                send 61
  3235.  
  3236. Return Value   If no error occurs, send() returns the total number of
  3237.           characters sent.  (Note that this may be less than the
  3238.           number indicated by len.) Otherwise, a value of SOCKET_ERROR
  3239.           is returned, and a specific error code may be retrieved by
  3240.           calling WSAGetLastError().
  3241.  
  3242. Error Codes                   WSANOTINITIALISED   A successful
  3243.                               WSAStartup() must occur before using
  3244.                               this API.
  3245.  
  3246.           WSAENETDOWN         The Windows Sockets implementation has
  3247.                               detected that the network subsystem has
  3248.                               failed.
  3249.  
  3250.           WSAEACCES           The requested address is a broadcast
  3251.                               address, but the appropriate flag was
  3252.                               not set.
  3253.  
  3254.           WSAEINTR            The (blocking) call was canceled via
  3255.                               WSACancelBlockingCall().
  3256.  
  3257.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  3258.                               in progress.
  3259.  
  3260.           WSAEFAULT           The buf argument is not in a valid part
  3261.                               of the user address space.
  3262.  
  3263.           WSAENETRESET        The connection must be reset because the
  3264.                               Windows Sockets implementation dropped
  3265.                               it.
  3266.  
  3267.           WSAENOBUFS          The Windows Sockets implementation
  3268.                               reports a buffer deadlock.
  3269.  
  3270.           WSAENOTCONN         The socket is not connected.
  3271.  
  3272.           WSAENOTSOCK         The descriptor is not a socket.
  3273.  
  3274.           WSAEOPNOTSUPP       MSG_OOB was specified, but the socket is
  3275.                               not of type SOCK_STREAM.
  3276.  
  3277.           WSAESHUTDOWN        The socket has been shutdown; it is not
  3278.                               possible to send() on a socket after
  3279.                               shutdown() has been invoked with how set
  3280.                               to 1 or 2.
  3281.  
  3282.           WSAEWOULDBLOCK      The socket is marked as non-blocking and
  3283.                               the requested operation would block.
  3284.  
  3285.           WSAEMSGSIZE         The socket is of type SOCK_DGRAM, and
  3286.                               the datagram is larger than the maximum
  3287.                               supported by the Windows Sockets
  3288.                               implementation.
  3289.  
  3290.           WSAEINVAL           The socket has not been bound with
  3291.                               bind().
  3292.  
  3293.  
  3294.  
  3295. 62 send
  3296.  
  3297.           WSAECONNABORTED     The virtual circuit was aborted due to
  3298.                               timeout or other failure.
  3299.  
  3300.           WSAECONNRESET       The virtual circuit was reset by the
  3301.                               remote side.
  3302.  
  3303.  
  3304. See Also  recv(), recvfrom(), socket(), sendto(), WSAStartup().
  3305.  
  3306.  
  3307.  
  3308.                                                              sendto 63
  3309.  
  3310. 4.1.20 sendto()
  3311. Description    Send data to a specific destination.
  3312.  
  3313.           #include <winsock.h>
  3314.  
  3315.           int PASCAL FAR sendto ( SOCKET s, const char FAR * buf, int
  3316.           len, int flags,
  3317.           const struct sockaddr FAR * to, int tolen );
  3318.  
  3319.  
  3320.           s         A descriptor identifying a socket.
  3321.  
  3322.           buf       A buffer containing the data to be transmitted.
  3323.  
  3324.           len       The length of the data in buf.
  3325.  
  3326.           flags     Specifies the way in which the call is made.
  3327.  
  3328.           to        An optional pointer to the address of the target
  3329.                     socket.
  3330.  
  3331.           tolen     The size of the address in to.
  3332.  
  3333. Remarks   sendto() is used on datagram or stream sockets and is used
  3334.           to write outgoing data on a socket.  For datagram sockets,
  3335.           care must be taken not to exceed the maximum IP packet size
  3336.           of the underlying subnets, which is given by the iMaxUdpDg
  3337.           element in the WSAData structure returned by WSAStartup().
  3338.           If the data is too long to pass atomically through the
  3339.           underlying protocol the error WSAEMSGSIZE is returned, and
  3340.           no data is transmitted.
  3341.  
  3342.           Note that the successful completion of a sendto() does not
  3343.           indicate that the data was successfully delivered.
  3344.  
  3345.           sendto() is normally used on a SOCK_DGRAM socket to send a
  3346.           datagram to a specific peer socket identified by the to
  3347.           parameter.  On a SOCK_STREAM socket, the to and tolen
  3348.           parameters are ignored; in this case the sendto() is
  3349.           equivalent to send().
  3350.  
  3351.           To send a broadcast (on a SOCK_DGRAM only), the address in
  3352.           the to parameter should be constructed using the special IP
  3353.           address INADDR_BROADCAST (defined in winsock.h) together
  3354.           with the intended port number.  It is generally inadvisable
  3355.           for a broadcast datagram to exceed the size at which
  3356.           fragmentation may occur, which implies that the data portion
  3357.           of the datagram (excluding headers) should not exceed 512
  3358.           bytes.
  3359.  
  3360.           If no buffer space is available within the transport system
  3361.           to hold the data to be transmitted, sendto() will block
  3362.           unless the socket has been placed in a non-blocking I/O
  3363.           mode.  On non-blocking SOCK_STREAM sockets, the number of
  3364.           bytes written may be between 1 and the requested length,
  3365.           depending on buffer availability on both the local and
  3366.  
  3367.  
  3368.  
  3369. 64 sendto
  3370.  
  3371.           foreign hosts.  The select() call may be used to determine
  3372.           when it is possible to send more data.
  3373.  
  3374.           Flags may be used to influence the behavior of the function
  3375.           invocation beyond the options specified for the associated
  3376.           socket.  That is, the semantics of this function are
  3377.           determined by the socket options and the flags parameter.
  3378.           The latter is constructed by or-ing any of the following
  3379.           values:
  3380.  
  3381.           Value     Meaning
  3382.           MSG_DONTROUTE
  3383.                     Specifies that the data should not be subject to
  3384.                     routing.  A Windows Sockets supplier may choose to
  3385.                     ignore this flag; see also the discussion of the
  3386.                     SO_DONTROUTE option in section .
  3387.  
  3388.           MSG_OOB   Send out-of-band data (SOCK_STREAM only; see also
  3389.                     section )
  3390.  
  3391.  
  3392. Return Value   If no error occurs, sendto() returns the total number
  3393.           of characters sent.  (Note that this may be less than the
  3394.           number indicated by len.) Otherwise, a value of SOCKET_ERROR
  3395.           is returned, and a specific error code may be retrieved by
  3396.           calling WSAGetLastError().
  3397.  
  3398. Error Codes                   WSANOTINITIALISED   A successful
  3399.                               WSAStartup() must occur before using
  3400.                               this API.
  3401.  
  3402.           WSAENETDOWN         The Windows Sockets implementation has
  3403.                               detected that the network subsystem has
  3404.                               failed.
  3405.  
  3406.           WSAEACCES           The requested address is a broadcast
  3407.                               address, but the appropriate flag was
  3408.                               not set.
  3409.  
  3410.           WSAEINTR            The (blocking) call was canceled via
  3411.                               WSACancelBlockingCall().
  3412.  
  3413.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  3414.                               in progress.
  3415.  
  3416.           WSAEFAULT           The buf or to parameters are not part of
  3417.                               the user address space, or the to
  3418.                               argument is too small (less than the
  3419.                               sizeof a struct sockaddr).
  3420.  
  3421.           WSAENETRESET        The connection must be reset because the
  3422.                               Windows Sockets implementation dropped
  3423.                               it.
  3424.  
  3425.           WSAENOBUFS          The Windows Sockets implementation
  3426.                               reports a buffer deadlock.
  3427.  
  3428.  
  3429.  
  3430.                                                              sendto 65
  3431.  
  3432.           WSAENOTCONN         The socket is not connected (SOCK_STREAM
  3433.                               only).
  3434.  
  3435.           WSAENOTSOCK         The descriptor is not a socket.
  3436.  
  3437.           WSAEOPNOTSUPP       MSG_OOB was specified, but the socket is
  3438.                               not of type SOCK_STREAM.
  3439.  
  3440.           WSAESHUTDOWN        The socket has been shutdown; it is not
  3441.                               possible to sendto() on a socket after
  3442.                               shutdown() has been invoked with how set
  3443.                               to 1 or 2.
  3444.  
  3445.           WSAEWOULDBLOCK      The socket is marked as non-blocking and
  3446.                               the requested operation would block.
  3447.  
  3448.           WSAEMSGSIZE         The socket is of type SOCK_DGRAM, and
  3449.                               the datagram is larger than the maximum
  3450.                               supported by the Windows Sockets
  3451.                               implementation.
  3452.  
  3453.           WSAECONNABORTED     The virtual circuit was aborted due to
  3454.                               timeout or other failure.
  3455.  
  3456.           WSAECONNRESET       The virtual circuit was reset by the
  3457.                               remote side.
  3458.  
  3459.           WSAEADDRNOTAVAIL    The specified address is not available
  3460.                               from the local machine.
  3461.  
  3462.           WSAEAFNOSUPPORT     Addresses in the specified family cannot
  3463.                               be used with this socket.
  3464.  
  3465.           WSAEDESTADDRREQ     A destination address is required.
  3466.  
  3467.           WSAENETUNREACH      The network can't be reached from this
  3468.                               host at this time.
  3469.  
  3470. See Also  recv(), recvfrom(), socket(), send(), WSAStartup().
  3471.  
  3472.  
  3473.  
  3474. 66 setsockopt
  3475.  
  3476. 4.1.21 setsockopt()
  3477. Description    Set a socket option.
  3478.  
  3479.           #include <winsock.h>
  3480.  
  3481.           int PASCAL FAR setsockopt ( SOCKET s, int level, int
  3482.           optname,
  3483.           const char FAR * optval, int optlen );
  3484.  
  3485.  
  3486.           s         A descriptor identifying a socket.
  3487.  
  3488.           level     The level at which the option is defined; the only
  3489.                     supported levels are SOL_SOCKET and IPPROTO_TCP.
  3490.  
  3491.           optname   The socket option for which the value is to be
  3492.                     set.
  3493.  
  3494.           optval    A pointer to the buffer in which the value for the
  3495.                     requested option is supplied.
  3496.  
  3497.           optlen    The size of the optval buffer.
  3498.  
  3499. Remarks   setsockopt() sets the current value for a socket option
  3500.           associated with a socket of any type, in any state.
  3501.           Although options may exist at multiple protocol levels, this
  3502.           specification only defines options that exist at the
  3503.           uppermost "socket'' level.  Options affect socket
  3504.           operations, such as whether expedited data is received in
  3505.           the normal data stream, whether broadcast messages may be
  3506.           sent on the socket, etc.
  3507.  
  3508.           There are two types of socket options: Boolean options that
  3509.           enable or disable a feature or behavior, and options which
  3510.           require an integer value or structure.  To enable a Boolean
  3511.           option, optval points to a nonzero integer.  To disable the
  3512.           option optval points to an integer equal to zero.  optlen
  3513.           should be equal to sizeof(int) for Boolean options.  For
  3514.           other options, optval points to the an integer or structure
  3515.           that contains the desired value for the option, and optlen
  3516.           is the length of the integer or structure.
  3517.  
  3518.           SO_LINGER controls the action taken when unsent data is
  3519.           queued on a socket and a closesocket() is performed.  See
  3520.           closesocket() for a description of the way in which the
  3521.           SO_LINGER settings affect the semantics of closesocket().
  3522.           The application sets the desired behavior by creating a
  3523.           struct linger (pointed to by the optval argument) with the
  3524.           following elements:
  3525.  
  3526.           struct linger {
  3527.                int  l_onoff;
  3528.                int  l_linger;
  3529.           }
  3530.  
  3531.           To enable SO_LINGER, the application should set l_onoff to a
  3532.           non-zero value, set l_linger to 0 or the desired timeout (in
  3533.  
  3534.  
  3535.  
  3536.                                                          setsockopt 67
  3537.  
  3538.           seconds), and call setsockopt().  To enable SO_DONTLINGER
  3539.           (i.e. disable SO_LINGER) l_onoff should be set to zero and
  3540.           setsockopt() should be called.
  3541.  
  3542.           By default, a socket may not be bound (see bind()) to a
  3543.           local address which is already in use.  On occasions,
  3544.           however, it may be desirable to "re-use" an address in this
  3545.           way.  Since every connection is uniquely identified by the
  3546.           combination of local and remote addresses, there is no
  3547.           problem with having two sockets bound to the same local
  3548.           address as long as the remote addresses are different.  To
  3549.           inform the Windows Sockets implementation that a bind() on a
  3550.           socket should not be disallowed because the desired address
  3551.           is already in use by another socket, the application should
  3552.           set the SO_REUSEADDR socket option for the socket before
  3553.           issuing the bind().  Note that the option is interpreted
  3554.           only at the time of the bind(): it is therefore unnecessary
  3555.           (but harmless) to set the option on a socket which is not to
  3556.           be bound to an existing address, and setting or resetting
  3557.           the option after the bind() has no effect on this or any
  3558.           other socket.
  3559.  
  3560.           An application may request that the Windows Sockets
  3561.           implementation enable the use of "keep-alive" packets on TCP
  3562.           connections by turning on the SO_KEEPALIVE socket option.  A
  3563.           Windows Sockets implementation need not support the use of
  3564.           keep-alives: if it does, the precise semantics are
  3565.           implementation-specific but should conform to section
  3566.           4.2.3.6 of RFC 1122: Requirements for Internet Hosts --
  3567.           Communication Layers.  If a connection is dropped as the
  3568.           result of "keep-alives" the error code WSAENETRESET is
  3569.           returned to any calls in progress on the socket, and any
  3570.           subsequent calls will fail with WSAENOTCONN.
  3571.  
  3572.           The TCP_NODELAY option disables the Nagle algorithm.  The
  3573.           Nagle algorithm is used to reduce the number of small
  3574.           packets sent by a host by buffering unacknowledged send data
  3575.           until a full-size packet can be sent.  However, for some
  3576.           applications this algorithm can impede performance, and
  3577.           TCP_NODELAY may be used to turn it off.  Application writers
  3578.           should not set TCP_NODELAY unless the impact of doing so is
  3579.           well-understood and desired, since setting TCP_NODELAY can
  3580.           have a significant negative impact of network performance.
  3581.           TCP_NODELAY is the only supported socket option which uses
  3582.           level IPPROTO_TCP; all other options use level SOL_SOCKET.
  3583.  
  3584.           Windows Sockets suppliers are encouraged (but not required)
  3585.           to supply output debug information if the SO_DEBUG option is
  3586.           set by an application.  The mechanism for generating the
  3587.           debug information and the form it takes are beyond the scope
  3588.           of this specification.
  3589.  
  3590.           The following options are supported for setsockopt().  The
  3591.           Type identifies the type of data addressed by optval.
  3592.  
  3593.                Value        Type     Meaning
  3594.  
  3595.  
  3596.  
  3597. 68 setsockopt
  3598.  
  3599.                SO_BROADCAS  BOOL     Allow transmission of
  3600.                T                     broadcast messages on the
  3601.                                      socket.
  3602.                SO_DEBUG     BOOL     Record debugging
  3603.                                      information.
  3604.                SO_DONTLING  BOOL     Don't block close waiting
  3605.                ER                    for unsent data to be sent.
  3606.                                      Setting this option is
  3607.                                      equivalent to setting
  3608.                                      SO_LINGER with l_onoff set
  3609.                                      to zero.
  3610.                SO_DONTROUT  BOOL     Don't route: send directly
  3611.                E                     to interface.
  3612.                SO_KEEPALIV  BOOL     Send keepalives
  3613.                E
  3614.                SO_LINGER    struct   Linger on close if unsent
  3615.                             linger   data is present
  3616.                             FAR *
  3617.                SO_OOBINLIN  BOOL     Receive out-of-band data in
  3618.                E                     the normal data stream.
  3619.                SO_RCVBUF    int      Specify buffer size for
  3620.                                      receives
  3621.                SO_REUSEADD  BOOL     Allow the socket to be bound
  3622.                R                     to an address which is
  3623.                                      already in use.  (See
  3624.                                      bind().)
  3625.                SO_SNDBUF    int      Specify buffer size for
  3626.                                      sends.
  3627.                TCP_NODELAY  BOOL     Disables the Nagle algorithm
  3628.                                      for send coalescing.
  3629.  
  3630.                BSD options not supported for setsockopt() are:
  3631.  
  3632.                Value        Type     Meaning
  3633.                SO_ACCEPTCO  BOOL     Socket is listening
  3634.                NN
  3635.                SO_ERROR     int      Get error status and clear
  3636.                SO_RCVLOWAT  int      Receive low water mark
  3637.                SO_RCVTIMEO  int      Receive timeout
  3638.                SO_SNDLOWAT  int      Send low water mark
  3639.                SO_SNDTIMEO  int      Send timeout
  3640.                SO_TYPE      int      Type of the socket
  3641.                IP_OPTIONS            Set options field in IP
  3642.                                      header.
  3643.  
  3644. Return Value   If no error occurs, setsockopt() returns 0.  Otherwise,
  3645.           a value of SOCKET_ERROR is returned, and a specific error
  3646.           code may be retrieved by calling WSAGetLastError().
  3647.  
  3648. Error Codes                   WSANOTINITIALISED   A successful
  3649.                               WSAStartup() must occur before using
  3650.                               this API.
  3651.  
  3652.           WSAENETDOWN         The Windows Sockets implementation has
  3653.                               detected that the network subsystem has
  3654.                               failed.
  3655.  
  3656.  
  3657.  
  3658.                                                          setsockopt 69
  3659.  
  3660.           WSAEFAULT           optval is not in a valid part of the
  3661.                               process address  space.
  3662.  
  3663.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  3664.                               in progress.
  3665.  
  3666.           WSAEINVAL           level is not valid, or the information
  3667.                               in optval is not valid.
  3668.  
  3669.           WSAENETRESET        Connection has timed out when
  3670.                               SO_KEEPALIVE is set.
  3671.  
  3672.           WSAENOPROTOOPT      The option is unknown or unsupported.
  3673.                               In particular, SO_BROADCAST is not
  3674.                               supported on sockets of type
  3675.                               SOCK_STREAM, while SO_DONTLINGER,
  3676.                               SO_KEEPALIVE, SO_LINGER and SO_OOBINLINE
  3677.                               are not supported on sockets of type
  3678.                               SOCK_DGRAM.
  3679.  
  3680.           WSAENOTCONN         Connection has been reset when
  3681.                               SO_KEEPALIVE is set.
  3682.  
  3683.           WSAENOTSOCK         The descriptor is not a socket.
  3684.  
  3685. See Also  bind(), getsockopt(), ioctlsocket(), socket(),
  3686.           WSAAsyncSelect().
  3687.  
  3688.  
  3689.  
  3690. 70 shutdown
  3691.  
  3692. 4.1.22 shutdown()
  3693. Description    Disable sends and/or receives on a socket.
  3694.  
  3695.           #include <winsock.h>
  3696.  
  3697.           int PASCAL FAR shutdown ( SOCKET s, int how );
  3698.  
  3699.  
  3700.           s         A descriptor identifying a socket.
  3701.  
  3702.           how       A flag that describes what types of operation will
  3703.                     no longer be allowed.
  3704.  
  3705. Remarks   shutdown() is used on all types of sockets to disable
  3706.           reception, transmission, or both.
  3707.  
  3708.           If how is 0, subsequent receives on the socket will be
  3709.           disallowed.  This has no effect on the lower protocol
  3710.           layers.  For TCP, the TCP window is not changed and incoming
  3711.           data will be accepted (but not acknowledged) until the
  3712.           window is exhausted.  For UDP, incoming datagrams are
  3713.           accepted and queued.  In no case will an ICMP error packet
  3714.           be generated.
  3715.  
  3716.           If how is 1, subsequent sends are disallowed.  For TCP
  3717.           sockets, a FIN will be sent.
  3718.  
  3719.           Setting how to 2 disables both sends and receives as
  3720.           described above.
  3721.  
  3722.           Note that shutdown() does not close the socket, and
  3723.           resources attached to the socket will not be freed until
  3724.           closesocket() is invoked.
  3725.  
  3726.  
  3727. Comments  shutdown() does not block regardless of the SO_LINGER
  3728.           setting on the socket.
  3729.  
  3730.           An application should not rely on being able to re-use a
  3731.           socket after it has been shut down.  In particular, a
  3732.           Windows Sockets implementation is not required to support
  3733.           the use of connect() on such a socket.
  3734.  
  3735. Return Value   If no error occurs, shutdown() returns 0.  Otherwise, a
  3736.           value of SOCKET_ERROR is returned, and a specific error code
  3737.           may be retrieved by calling WSAGetLastError().
  3738.  
  3739. Error Codes                   WSANOTINITIALISED   A successful
  3740.                               WSAStartup() must occur before using
  3741.                               this API.
  3742.  
  3743.           WSAENETDOWN         The Windows Sockets implementation has
  3744.                               detected that the network subsystem has
  3745.                               failed.
  3746.  
  3747.           WSAEINVAL           how is not valid.
  3748.  
  3749.  
  3750.  
  3751.                                                            shutdown 71
  3752.  
  3753.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  3754.                               in progress.
  3755.  
  3756.           WSAENOTCONN         The socket is not connected (SOCK_STREAM
  3757.                               only).
  3758.  
  3759.           WSAENOTSOCK         The descriptor is not a socket.
  3760.  
  3761. See Also  connect(), socket().
  3762.  
  3763.  
  3764.  
  3765. 72 socket
  3766.  
  3767. 4.1.23 socket()
  3768. Description    Create a socket.
  3769.  
  3770.           #include <winsock.h>
  3771.  
  3772.           SOCKET PASCAL FAR socket ( int af, int type, int protocol );
  3773.  
  3774.  
  3775.           af        An address format specification.  The only format
  3776.                     currently supported is PF_INET, which is the ARPA
  3777.                     Internet address format.
  3778.  
  3779.           type      A type specification for the new socket.
  3780.  
  3781.           protocol  A particular protocol to be used with the socket,
  3782.                     or 0 if the caller does not wish to specify a
  3783.                     protocol.
  3784.  
  3785. Remarks   socket() allocates a socket descriptor of the specified
  3786.           address family, data type and protocol, as well as related
  3787.           resources.  If a protocol is not specified (i.e. equal to
  3788.           0), the default for the specified connection mode is used.
  3789.  
  3790.           Only a single protocol exists to support a particular socket
  3791.           type using a given address format.  However, the address
  3792.           family may be given as AF_UNSPEC (unspecified), in which
  3793.           case the protocol parameter must be specified.  The protocol
  3794.           number to use is particular to the "communication domain''
  3795.           in which communication is to take place.
  3796.  
  3797.           The following type specifications are supported:
  3798.  
  3799.                Type           Explanation
  3800.                SOCK_STREAM    Provides sequenced, reliable, two-way,
  3801.                               connection-based byte streams with an
  3802.                               out-of-band data transmission mechanism.
  3803.                               Uses TCP for the Internet address
  3804.                               family.
  3805.  
  3806.                SOCK_DGRAM     Supports datagrams, which are
  3807.                               connectionless, unreliable buffers of a
  3808.                               fixed (typically small) maximum length.
  3809.                               Uses UDP for the Internet address
  3810.                               family.
  3811.  
  3812.  
  3813.           Sockets of type SOCK_STREAM are full-duplex byte streams.  A
  3814.           stream socket must be in a connected state before any data
  3815.           may be sent or received on it.  A connection to another
  3816.           socket is created with a connect() call.  Once connected,
  3817.           data may be transferred using send() and recv() calls.  When
  3818.           a session has been completed, a closesocket() must be
  3819.           performed.  Out-of-band data may also be transmitted as
  3820.           described in send() and received as described in recv().
  3821.  
  3822.           The communications protocols used to implement a SOCK_STREAM
  3823.           ensure that data is not lost or duplicated.  If data for
  3824.  
  3825.  
  3826.  
  3827.                                                              socket 73
  3828.  
  3829.           which the peer protocol has buffer space cannot be
  3830.           successfully transmitted within a reasonable length of time,
  3831.           the connection is considered broken and subsequent calls
  3832.           will fail with the error code set to WSAETIMEDOUT.
  3833.  
  3834.           SOCK_DGRAM sockets allow sending and receiving of datagrams
  3835.           to and from arbitrary peers using sendto() and recvfrom().
  3836.           If such a socket is connect()ed to a specific peer,
  3837.           datagrams may be send to that peer send() and may be
  3838.           received from (only) this peer using recv().
  3839.  
  3840.  
  3841. Return Value   If no error occurs, socket() returns a descriptor
  3842.           referencing the new socket.  Otherwise, a value of
  3843.           INVALID_SOCKET is returned, and a specific error code may be
  3844.           retrieved by calling WSAGetLastError().
  3845.  
  3846. Error Codes                   WSANOTINITIALISED   A successful
  3847.                               WSAStartup() must occur before using
  3848.                               this API.
  3849.  
  3850.           WSAENETDOWN         The Windows Sockets implementation has
  3851.                               detected that the network subsystem has
  3852.                               failed.
  3853.  
  3854.           WSAEAFNOSUPPORT     The specified address family is not
  3855.                               supported.
  3856.  
  3857.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  3858.                               in progress.
  3859.  
  3860.           WSAEMFILE           No more file descriptors are available.
  3861.  
  3862.           WSAENOBUFS          No buffer space is available.  The
  3863.                               socket cannot be created.
  3864.  
  3865.           WSAEPROTONOSUPPORT  The specified protocol is not supported.
  3866.  
  3867.           WSAEPROTOTYPE       The specified protocol is the wrong type
  3868.                               for this socket.
  3869.  
  3870.           WSAESOCKTNOSUPPORT  The specified socket type is not
  3871.                               supported in this address family.
  3872.  
  3873. See Also  accept(), bind(), connect(), getsockname(), getsockopt(),
  3874.           setsockopt(), listen(), recv(), recvfrom(), select(),
  3875.           send(), sendto(), shutdown(), ioctlsocket().
  3876.  
  3877.  
  3878.  
  3879. 74 gethostbyaddr
  3880.  
  3881.  
  3882. 4.2 Database Routines
  3883. 4.2.1 gethostbyaddr()
  3884. Description    Get host information corresponding to an address.
  3885.  
  3886.           #include <winsock.h>
  3887.  
  3888.           struct hostent FAR * PASCAL FAR gethostbyaddr ( const char
  3889.           FAR * addr, int len,  int type );
  3890.  
  3891.  
  3892.           addr      A pointer to an address in network byte order.
  3893.  
  3894.           len       The length of the address, which must be 4 for
  3895.                     PF_INET addresses.
  3896.  
  3897.           type      The type of the address, which must be PF_INET.
  3898.  
  3899. Remarks   gethostbyaddr() returns a pointer to the following structure
  3900.           which contains the name(s) and address which correspond to
  3901.           the given address.
  3902.  
  3903.           struct hostent {
  3904.                char FAR *     h_name;
  3905.                char FAR * FAR *    h_aliases;
  3906.                short     h_addrtype;
  3907.                short     h_length;
  3908.                char FAR * FAR *    h_addr_list;
  3909.           };
  3910.  
  3911.           The members of this structure are:
  3912.           Element   Usage
  3913.           h_name    Official name of the host (PC).
  3914.           h_aliases A NULL-terminated array of alternate names.
  3915.           h_addrtype     The type of address being returned; for
  3916.                     Windows Sockets this is always PF_INET.
  3917.           h_length  The length, in bytes, of each address; for
  3918.                     PF_INET, this is always 4.
  3919.           h_addr_list    A NULL-terminated list of addresses for the
  3920.                     host.  Addresses are returned in network byte
  3921.                     order.
  3922.  
  3923.           The macro h_addr is defined to be h_addr_list[0] for
  3924.           compatibility with older software.
  3925.  
  3926.           The pointer which is returned points to a structure which is
  3927.           allocated by the Windows Sockets implementation.  The
  3928.           application must never attempt to modify this structure or
  3929.           to free any of its components.  Furthermore, only one copy
  3930.           of this structure is allocated per thread, and so the
  3931.           application should copy any information which it needs
  3932.           before issuing any other Windows Sockets API calls.
  3933.  
  3934.  
  3935. Return Value   If no error occurs, gethostbyaddr() returns a pointer
  3936.           to the hostent structure described above.  Otherwise it
  3937.  
  3938.  
  3939.  
  3940.                                                       gethostbyaddr 75
  3941.  
  3942.           returns a NULL pointer and a specific error number may be
  3943.           retrieved by calling WSAGetLastError().
  3944.  
  3945. Error Codes                   WSANOTINITIALISED   A successful
  3946.                               WSAStartup() must occur before using
  3947.                               this API.
  3948.  
  3949.           WSAENETDOWN         The Windows Sockets implementation has
  3950.                               detected that the network subsystem has
  3951.                               failed.
  3952.  
  3953.           WSAHOST_NOT_FOUND   Authoritative Answer Host not found.
  3954.  
  3955.           WSATRY_AGAIN        Non-Authoritative Host not found, or
  3956.                               SERVERFAIL.
  3957.  
  3958.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  3959.                               REFUSED, NOTIMP.
  3960.  
  3961.           WSANO_DATA          Valid name, no data record of requested
  3962.                               type.
  3963.  
  3964.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  3965.                               in progress.
  3966.  
  3967.           WSAEINTR            The (blocking) call was canceled via
  3968.                               WSACancelBlockingCall().
  3969.  
  3970. See Also  WSAAsyncGetHostByAddr(), gethostbyname(),
  3971.  
  3972.  
  3973.  
  3974. 76 gethostbyname
  3975.  
  3976. 4.2.2 gethostbyname()
  3977. Description    Get host information corresponding to a hostname.
  3978.  
  3979.           #include <winsock.h>
  3980.  
  3981.           struct hostent FAR * PASCAL FAR gethostbyname ( const char
  3982.           FAR * name );
  3983.  
  3984.  
  3985.           name      A pointer to the name of the host.
  3986.  
  3987. Remarks   gethostbyname() returns a pointer to a hostent structure as
  3988.           described under gethostbyaddr().  The contents of this
  3989.           structure correspond to the hostname name.
  3990.  
  3991.           The pointer which is returned points to a structure which is
  3992.           allocated by the Windows Sockets implementation.  The
  3993.           application must never attempt to modify this structure or
  3994.           to free any of its components.  Furthermore, only one copy
  3995.           of this structure is allocated per thread, and so the
  3996.           application should copy any information which it needs
  3997.           before issuing any other Windows Sockets API calls.
  3998.  
  3999.           A gethostbyname() implementation must not resolve IP address
  4000.           strings passed to it.  Such a request should be treated
  4001.           exactly as if an unknown host name were passed.  An
  4002.           application with an IP address string to resolve should use
  4003.           inet_addr() to convert the string to an IP address, then
  4004.           gethostbyaddr() to obtain the hostent structure.
  4005.  
  4006.  
  4007. Return Value   If no error occurs, gethostbyname() returns a pointer
  4008.           to the hostent structure described above.  Otherwise it
  4009.           returns a NULL pointer and a specific error number may be
  4010.           retrieved by calling WSAGetLastError().
  4011.  
  4012. Error Codes                   WSANOTINITIALISED   A successful
  4013.                               WSAStartup() must occur before using
  4014.                               this API.
  4015.  
  4016.           WSAENETDOWN         The Windows Sockets implementation has
  4017.                               detected that the network subsystem has
  4018.                               failed.
  4019.  
  4020.           WSAHOST_NOT_FOUND   Authoritative Answer Host not found.
  4021.  
  4022.           WSATRY_AGAIN        Non-Authoritative Host not found, or
  4023.                               SERVERFAIL.
  4024.  
  4025.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  4026.                               REFUSED, NOTIMP.
  4027.  
  4028.           WSANO_DATA          Valid name, no data record of requested
  4029.                               type.
  4030.  
  4031.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  4032.                               in progress.
  4033.  
  4034.  
  4035.  
  4036.                                                         gethostname 77
  4037.  
  4038.  
  4039.           WSAEINTR            The (blocking) call was canceled via
  4040.                               WSACancelBlockingCall().
  4041.  
  4042.  
  4043. See Also  WSAAsyncGetHostByName(), gethostbyaddr()
  4044.  
  4045.  
  4046.  
  4047. 78 gethostbyname
  4048.  
  4049.  
  4050. 4.2.3 gethostname()
  4051. Description    Return the standard host name for the local machine.
  4052.  
  4053.           #include <winsock.h>
  4054.  
  4055.           int PASCAL FAR gethostname ( char FAR * name, int namelen );
  4056.  
  4057.           name      A pointer to a buffer that will receive the host
  4058.                     name.
  4059.  
  4060.           namelen   The length of the buffer.
  4061.  
  4062. Remarks   This routine returns the name of the local host into the
  4063.           buffer specified by the name parameter.  The host name is
  4064.           returned as a null-terminated string.  The form of the host
  4065.           name is dependent on the Windows Sockets implementation--it
  4066.           may be a simple host name, or it may be a fully qualified
  4067.           domain name.  However, it is guaranteed that the name
  4068.           returned will be successfully parsed by gethostbyname() and
  4069.           WSAAsyncGetHostByName().
  4070.  
  4071. Return Value   If no error occurs, gethostname() returns 0, otherwise
  4072.           it returns SOCKET_ERROR and a specific error code may be
  4073.           retrieved by calling WSAGetLastError().
  4074.  
  4075. Error Codes                   WSAEFAULT The namelen parameter is too
  4076.                               small
  4077.  
  4078.           WSANOTINITIALISED   A successful WSAStartup() must occur
  4079.                               before using this API.
  4080.  
  4081.           WSAENETDOWN         The Windows Sockets implementation has
  4082.                               detected that the network subsystem has
  4083.                               failed.
  4084.  
  4085.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  4086.                               in progress.
  4087.  
  4088. See Also  gethostbyname(), WSAAsyncGetHostByName().
  4089.  
  4090.  
  4091.  
  4092.                                                      getprotobyname 79
  4093.  
  4094. 4.2.4 getprotobyname()
  4095. Description    Get protocol information corresponding to a protocol
  4096.           name.
  4097.  
  4098.           #include <winsock.h>
  4099.  
  4100.           struct protoent FAR * PASCAL FAR getprotobyname ( const char
  4101.           FAR * name );
  4102.  
  4103.  
  4104.           name      A pointer to a protocol name.
  4105.  
  4106. Remarks   getprotobyname() returns a pointer to the following
  4107.           structure which contains the name(s) and protocol number
  4108.           which correspond to the given protocol name.
  4109.  
  4110.           struct protoent {
  4111.                char FAR *     p_name;
  4112.                char FAR * FAR *    p_aliases;
  4113.                short     p_proto;
  4114.           };
  4115.  
  4116.           The members of this structure are:
  4117.           Element   Usage
  4118.           p_name    Official name of the protocol.
  4119.           p_aliases A NULL-terminated array of alternate names.
  4120.           p_proto   The protocol number, in host byte order.
  4121.  
  4122.           The pointer which is returned points to a structure which is
  4123.           allocated by the Windows Sockets library.  The application
  4124.           must never attempt to modify this structure or to free any
  4125.           of its components.  Furthermore only one copy of this
  4126.           structure is allocated per thread, and so the application
  4127.           should copy any information which it needs before issuing
  4128.           any other Windows Sockets API calls.
  4129.  
  4130.  
  4131. Return Value   If no error occurs, getprotobyname() returns a pointer
  4132.           to the protoent structure described above.  Otherwise it
  4133.           returns a NULL pointer and a specific error number may be
  4134.           retrieved by calling WSAGetLastError().
  4135.  
  4136. Error Codes                   WSANOTINITIALISED   A successful
  4137.                               WSAStartup() must occur before using
  4138.                               this API.
  4139.  
  4140.           WSAENETDOWN         The Windows Sockets implementation has
  4141.                               detected that the network subsystem has
  4142.                               failed.
  4143.  
  4144.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  4145.                               REFUSED, NOTIMP.
  4146.  
  4147.           WSANO_DATA          Valid name, no data record of requested
  4148.                               type.
  4149.  
  4150.  
  4151.  
  4152. 80 getprotobyname
  4153.  
  4154.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  4155.                               in progress.
  4156.  
  4157.           WSAEINTR            The (blocking) call was canceled via
  4158.                               WSACancelBlockingCall().
  4159.  
  4160.  
  4161. See Also  WSAAsyncGetProtoByName(), getprotobynumber()
  4162.  
  4163.  
  4164.  
  4165.                                                    getprotobynumber 81
  4166.  
  4167. 4.2.5 getprotobynumber()
  4168. Description    Get protocol information corresponding to a protocol
  4169.           number.
  4170.  
  4171.           #include <winsock.h>
  4172.  
  4173.           struct protoent FAR * PASCAL FAR getprotobynumber ( int
  4174.           number );
  4175.  
  4176.  
  4177.           number    A protocol number, in host byte order.
  4178.  
  4179. Remarks   This function returns a pointer to a protoent structure as
  4180.           described above in getprotobyname().  The contents of the
  4181.           structure correspond to the given protocol number.
  4182.  
  4183.           The pointer which is returned points to a structure which is
  4184.           allocated by the Windows Sockets implementation.  The
  4185.           application must never attempt to modify this structure or
  4186.           to free any of its components.  Furthermore, only one copy
  4187.           of this structure is allocated per thread, and so the
  4188.           application should copy any information which it needs
  4189.           before issuing any other Windows Sockets API calls.
  4190.  
  4191.  
  4192. Return Value   If no error occurs, getprotobynumber() returns a
  4193.           pointer to the protoent structure described above.
  4194.           Otherwise it returns a NULL pointer and a specific error
  4195.           number may be retrieved by calling WSAGetLastError().
  4196.  
  4197. Error Codes                   WSANOTINITIALISED   A successful
  4198.                               WSAStartup() must occur before using
  4199.                               this API.
  4200.  
  4201.           WSAENETDOWN         The Windows Sockets implementation has
  4202.                               detected that the network subsystem has
  4203.                               failed.
  4204.  
  4205.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  4206.                               REFUSED, NOTIMP.
  4207.  
  4208.           WSANO_DATA          Valid name, no data record of requested
  4209.                               type.
  4210.  
  4211.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  4212.                               in progress.
  4213.  
  4214.           WSAEINTR            The (blocking) call was canceled via
  4215.                               WSACancelBlockingCall().
  4216.  
  4217. See Also  WSAAsyncGetProtoByNumber(), getprotobyname()
  4218.  
  4219.  
  4220.  
  4221. 82 getservbyname
  4222.  
  4223. 4.2.6 getservbyname()
  4224. Description    Get service information corresponding to a service name
  4225.           and protocol.
  4226.  
  4227.           #include <winsock.h>
  4228.  
  4229.           struct servent FAR * PASCAL FAR getservbyname ( const char
  4230.           FAR * name,
  4231.           const char FAR * proto );
  4232.  
  4233.  
  4234.           name      A pointer to a service name.
  4235.  
  4236.           proto     An optional pointer to a protocol name.  If this
  4237.                     is NULL, getservbyname() returns the first service
  4238.                     entry for which the name matches the s_name or one
  4239.                     of the s_aliases.  Otherwise getservbyname()
  4240.                     matches both the name and the proto.
  4241.  
  4242. Remarks   getservbyname() returns a pointer to the following structure
  4243.           which contains the name(s) and service number which
  4244.           correspond to the given service name.
  4245.  
  4246.           struct servent {
  4247.                char FAR *     s_name;
  4248.                char FAR * FAR *    s_aliases;
  4249.                short     s_port;
  4250.                char FAR *     s_proto;
  4251.           };
  4252.  
  4253.           The members of this structure are:
  4254.           Element   Usage
  4255.           s_name    Official name of the service.
  4256.           s_aliases A NULL-terminated array of alternate names.
  4257.           s_port    The port number at which the service may be
  4258.                     contacted.  Port numbers are returned in network
  4259.                     byte order.
  4260.           s_proto   The name of the protocol to use when contacting
  4261.                     the service.
  4262.  
  4263.           The pointer which is returned points to a structure which is
  4264.           allocated by the Windows Sockets library.  The application
  4265.           must never attempt to modify this structure or to free any
  4266.           of its components.  Furthermore only one copy of this
  4267.           structure is allocated per thread, and so the application
  4268.           should copy any information which it needs before issuing
  4269.           any other Windows Sockets API calls.
  4270.  
  4271.  
  4272. Return Value   If no error occurs, getservbyname() returns a pointer
  4273.           to the servent structure described above.  Otherwise it
  4274.           returns a NULL pointer and a specific error number may be
  4275.           retrieved by calling WSAGetLastError().
  4276.  
  4277. Error Codes                   WSANOTINITIALISED   A successful
  4278.                               WSAStartup() must occur before using
  4279.                               this API.
  4280.  
  4281.  
  4282.  
  4283.                                                       getservbyname 83
  4284.  
  4285.  
  4286.           WSAENETDOWN         The Windows Sockets implementation has
  4287.                               detected that the network subsystem has
  4288.                               failed.
  4289.  
  4290.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  4291.                               REFUSED, NOTIMP.
  4292.  
  4293.           WSANO_DATA          Valid name, no data record of requested
  4294.                               type.
  4295.  
  4296.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  4297.                               in progress.
  4298.  
  4299.           WSAEINTR            The (blocking) call was canceled via
  4300.                               WSACancelBlockingCall().
  4301.  
  4302.  
  4303. See Also  WSAAsyncGetServByName(), getservbyport()
  4304.  
  4305.  
  4306.  
  4307. 84 getservbyport
  4308.  
  4309. 4.2.7 getservbyport()
  4310. Description    Get service information corresponding to a port and
  4311.           protocol.
  4312.  
  4313.           #include <winsock.h>
  4314.  
  4315.           struct servent FAR * PASCAL FAR getservbyport ( int port,
  4316.           const char FAR * proto );
  4317.  
  4318.  
  4319.           port      The port for a service, in network byte order.
  4320.  
  4321.           proto     An optional pointer to a protocol name.  If this
  4322.                     is NULL, getservbyport() returns the first service
  4323.                     entry for which the port matches the s_port.
  4324.                     Otherwise getservbyport() matches both the port
  4325.                     and the proto.
  4326.  
  4327. Remarks   getservbyport() returns a pointer a servent structure as
  4328.           described above for getservbyname().
  4329.  
  4330.           The pointer which is returned points to a structure which is
  4331.           allocated by the Windows Sockets implementation.  The
  4332.           application must never attempt to modify this structure or
  4333.           to free any of its components.  Furthermore, only one copy
  4334.           of this structure is allocated per thread, and so the
  4335.           application should copy any information which it needs
  4336.           before issuing any other Windows Sockets API calls.
  4337.  
  4338.  
  4339. Return Value   If no error occurs, getservbyport() returns a pointer
  4340.           to the servent structure described above.  Otherwise it
  4341.           returns a NULL pointer and a specific error number may be
  4342.           retrieved by calling WSAGetLastError().
  4343.  
  4344. Error Codes                   WSANOTINITIALISED   A successful
  4345.                               WSAStartup() must occur before using
  4346.                               this API.
  4347.  
  4348.           WSAENETDOWN         The Windows Sockets implementation has
  4349.                               detected that the network subsystem has
  4350.                               failed.
  4351.  
  4352.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  4353.                               REFUSED, NOTIMP.
  4354.  
  4355.           WSANO_DATA          Valid name, no data record of requested
  4356.                               type.
  4357.  
  4358.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  4359.                               in progress.
  4360.  
  4361.           WSAEINTR            The (blocking) call was canceled via
  4362.                               WSACancelBlockingCall().
  4363.  
  4364.  
  4365. See Also  WSAAsyncGetServByPort(), getservbyname()
  4366.  
  4367.  
  4368.  
  4369.                                               WSAAsyncGetHostByAddr 85
  4370.  
  4371.  
  4372. 4.3 Microsoft Windows-specific Extensions
  4373. 4.3.1 WSAAsyncGetHostByAddr()
  4374. Description    Get host information corresponding to an address -
  4375.           asynchronous version.
  4376.  
  4377.           #include <winsock.h>
  4378.  
  4379.           HANDLE PASCAL FAR WSAAsyncGetHostByAddr ( HWND hWnd,
  4380.           unsigned int wMsg,  const char FAR * addr, int len, int
  4381.           type, char FAR * buf, int buflen );
  4382.  
  4383.  
  4384.           hWnd      The handle of the window which should receive a
  4385.                     message when the asynchronous request completes.
  4386.  
  4387.           wMsg      The message to be received when the asynchronous
  4388.                     request completes.
  4389.  
  4390.           addr      A pointer to the network address for the host.
  4391.                     Host addresses are stored in network byte order.
  4392.  
  4393.           len       The length of the address, which must be 4 for
  4394.                     PF_INET.
  4395.  
  4396.           type      The type of the address, which must be PF_INET.
  4397.  
  4398.           buf       A pointer to the data area to receive the hostent
  4399.                     data.  Note that this must be larger than the size
  4400.                     of a hostent structure.  This is because the data
  4401.                     area supplied is used by the Windows Sockets
  4402.                     implementation to contain not only a hostent
  4403.                     structure but any and all of the data which is
  4404.                     referenced by members of the hostent structure.
  4405.                     It is recommended that you supply a buffer of
  4406.                     MAXGETHOSTSTRUCT bytes.
  4407.  
  4408.           buflen    The size of data area buf above.
  4409.  
  4410. Remarks   This function is an asynchronous version of gethostbyaddr(),
  4411.           and is used to retrieve host name and address information
  4412.           corresponding to a network address.  The Windows Sockets
  4413.           implementation initiates the operation and returns to the
  4414.           caller immediately, passing back an asynchronous task handle
  4415.           which the application may use to identify the operation.
  4416.           When the operation is completed, the results (if any) are
  4417.           copied into the buffer provided by the caller and a message
  4418.           is sent to the application's window.
  4419.  
  4420.           When the asynchronous operation is complete the
  4421.           application's window hWnd receives message wMsg.  The wParam
  4422.           argument contains the asynchronous task handle as returned
  4423.           by the original function call.  The high 16 bits of lParam
  4424.           contain any error code.  The error code may be any error as
  4425.           defined in winsock.h.  An error code of zero indicates
  4426.           successful completion of the asynchronous operation.  On
  4427.           successful completion, the buffer supplied to the original
  4428.  
  4429.  
  4430.  
  4431. 86 WSAAsyncGetHostByAddr
  4432.  
  4433.           function call contains a hostent structure.  To access the
  4434.           elements of this structure, the original buffer address
  4435.           should be cast to a hostent structure pointer and accessed
  4436.           as appropriate.
  4437.  
  4438.           Note that if the error code is WSAENOBUFS, it indicates that
  4439.           the size of the buffer specified by buflen in the original
  4440.           call was too small to contain all the resultant information.
  4441.           In this case, the low 16 bits of lParam contain the size of
  4442.           buffer required to supply ALL the requisite information.  If
  4443.           the application decides that the partial data is inadequate,
  4444.           it may reissue the WSAAsyncGetHostByAddr() function call
  4445.           with a buffer large enough to receive all the desired
  4446.           information (i.e.  no smaller than the low 16 bits of
  4447.           lParam).
  4448.  
  4449.           The error code and buffer length should be extracted from
  4450.           the lParam using the macros  WSAGETASYNCERROR and
  4451.           WSAGETASYNCBUFLEN, defined in winsock.h as:
  4452.  
  4453.           #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  4454.           #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  4455.  
  4456.           The use of these macros will maximize the portability of the
  4457.           source code for the application.
  4458.  
  4459. Return Value   The return value specifies whether or not the
  4460.           asynchronous operation was successfully initiated.  Note
  4461.           that it does not imply success or failure of the operation
  4462.           itself.
  4463.  
  4464.           If the operation was successfully initiated,
  4465.           WSAAsyncGetHostByAddr() returns a nonzero value of type
  4466.           HANDLE which is the asynchronous task handle for the
  4467.           request.  This value can be used in two ways.  It can be
  4468.           used to cancel the operation using WSACancelAsyncRequest().
  4469.           It can also be used to match up asynchronous operations and
  4470.           completion messages, by examining the wParam message
  4471.           argument.
  4472.  
  4473.           If the asynchronous operation could not be initiated,
  4474.           WSAAsyncGetHostByAddr() returns a zero value, and a specific
  4475.           error number may be retrieved by calling WSAGetLastError().
  4476.  
  4477. Comments  The buffer supplied to this function is used by the Windows
  4478.           Sockets implementation to construct a hostent structure
  4479.           together with the contents of data areas referenced by
  4480.           members of the same hostent structure.  To avoid the
  4481.           WSAENOBUFS error noted above, the application should provide
  4482.           a buffer of at least MAXGETHOSTSTRUCT bytes (as defined in
  4483.           winsock.h).
  4484.  
  4485. Notes For
  4486. Windows Sockets
  4487. Suppliers It is the responsibility of the Windows Sockets
  4488.           implementation to ensure that messages are successfully
  4489.           posted to the application.  If a PostMessage() operation
  4490.  
  4491.  
  4492.  
  4493.                                               WSAAsyncGetHostByAddr 87
  4494.  
  4495.           fails, the Windows Sockets implementation must re-post that
  4496.           message as long as the window exists.
  4497.  
  4498.           Windows Sockets suppliers should use the WSAMAKEASYNCREPLY
  4499.           macro when constructing the lParam in the message.
  4500.  
  4501. Error Codes    The following error codes may be set when an
  4502.           application window receives a message.  As described above,
  4503.           they may be extracted from the lParam in the reply message
  4504.           using the WSAGETASYNCERROR macro.
  4505.  
  4506.           WSAENETDOWN         The Windows Sockets implementation has
  4507.                               detected that the network subsystem has
  4508.                               failed.
  4509.  
  4510.           WSAENOBUFS          No/insufficient buffer space is
  4511.                               available
  4512.  
  4513.           WSAHOST_NOT_FOUND   Authoritative Answer Host not found.
  4514.  
  4515.           WSATRY_AGAIN        Non-Authoritative Host not found, or
  4516.                               SERVERFAIL.
  4517.  
  4518.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  4519.                               REFUSED, NOTIMP.
  4520.  
  4521.           WSANO_DATA          Valid name, no data record of requested
  4522.                               type.
  4523.  
  4524.           The following errors may occur at the time of the function
  4525.           call, and indicate that the asynchronous operation could not
  4526.           be initiated.
  4527.  
  4528.           WSANOTINITIALISED   A successful WSAStartup() must occur
  4529.                               before using this API.
  4530.  
  4531.           WSAENETDOWN         The Windows Sockets implementation has
  4532.                               detected that the network subsystem has
  4533.                               failed.
  4534.  
  4535.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  4536.                               in progress.
  4537.  
  4538.           WSAEWOULDBLOCK      The asynchronous operation cannot be
  4539.                               scheduled at this time due to resource
  4540.                               or other constraints within the Windows
  4541.                               Sockets implementation.
  4542.  
  4543. See Also  gethostbyaddr(), WSACancelAsyncRequest()
  4544.  
  4545.  
  4546.  
  4547. 88 WSAAsyncGetHostByName
  4548.  
  4549. 4.3.2 WSAAsyncGetHostByName()
  4550. Description    Get host information corresponding to a hostname -
  4551.           asynchronous version.
  4552.  
  4553.           #include <winsock.h>
  4554.  
  4555.           HANDLE PASCAL FAR WSAAsyncGetHostByName ( HWND hWnd,
  4556.           unsigned int wMsg,  const char FAR * name, char FAR * buf,
  4557.           int buflen );
  4558.  
  4559.  
  4560.           hWnd      The handle of the window which should receive a
  4561.                     message when the asynchronous request completes.
  4562.  
  4563.           wMsg      The message to be received when the asynchronous
  4564.                     request completes.
  4565.  
  4566.           name      A pointer to the name of the host.
  4567.  
  4568.           buf       A pointer to the data area to receive the hostent
  4569.                     data.  Note that this must be larger than the size
  4570.                     of a hostent structure.  This is because the data
  4571.                     area supplied is used by the Windows Sockets
  4572.                     implementation to contain not only a hostent
  4573.                     structure but any and all of the data which is
  4574.                     referenced by members of the hostent structure.
  4575.                     It is recommended that you supply a buffer of
  4576.                     MAXGETHOSTSTRUCT bytes.
  4577.  
  4578.           buflen    The size of data area buf above.
  4579.  
  4580. Remarks   This function is an asynchronous version of gethostbyname(),
  4581.           and is used to retrieve host name and address information
  4582.           corresponding to a hostname.  The Windows Sockets
  4583.           implementation initiates the operation and returns to the
  4584.           caller immediately, passing back an asynchronous task handle
  4585.           which the application may use to identify the operation.
  4586.           When the operation is completed, the results (if any) are
  4587.           copied into the buffer provided by the caller and a message
  4588.           is sent to the application's window.
  4589.  
  4590.           When the asynchronous operation is complete the
  4591.           application's window hWnd receives message wMsg.  The wParam
  4592.           argument contains the asynchronous task handle as returned
  4593.           by the original function call.  The high 16 bits of lParam
  4594.           contain any error code.  The error code may be any error as
  4595.           defined in winsock.h.  An error code of zero indicates
  4596.           successful completion of the asynchronous operation.  On
  4597.           successful completion, the buffer supplied to the original
  4598.           function call contains a hostent structure.  To access the
  4599.           elements of this structure, the original buffer address
  4600.           should be cast to a hostent structure pointer and accessed
  4601.           as appropriate.
  4602.  
  4603.           Note that if the error code is WSAENOBUFS, it indicates that
  4604.           the size of the buffer specified by buflen in the original
  4605.           call was too small to contain all the resultant information.
  4606.  
  4607.  
  4608.  
  4609.                                               WSAAsyncGetHostByName 89
  4610.  
  4611.           In this case, the low 16 bits of lParam contain the size of
  4612.           buffer required to supply ALL the requisite information.  If
  4613.           the application decides that the partial data is inadequate,
  4614.           it may reissue the WSAAsyncGetHostByName() function call
  4615.           with a buffer large enough to receive all the desired
  4616.           information (i.e. no smaller than the low 16 bits of
  4617.           lParam).
  4618.  
  4619.           The error code and buffer length should be extracted from
  4620.           the lParam using the macros  WSAGETASYNCERROR and
  4621.           WSAGETASYNCBUFLEN, defined in winsock.h as:
  4622.  
  4623.           #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  4624.           #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  4625.  
  4626.           The use of these macros will maximize the portability of the
  4627.           source code for the application.
  4628.  
  4629.  
  4630. Return Value   The return value specifies whether or not the
  4631.           asynchronous operation was successfully initiated.  Note
  4632.           that it does not imply success or failure of the operation
  4633.           itself.
  4634.  
  4635.           If the operation was successfully initiated,
  4636.           WSAAsyncGetHostByName() returns a nonzero value of type
  4637.           HANDLE which is the asynchronous task handle for the
  4638.           request.  This value can be used in two ways.  It can be
  4639.           used to cancel the operation using WSACancelAsyncRequest().
  4640.           It can also be used to match up asynchronous operations and
  4641.           completion messages, by examining the wParam message
  4642.           argument.
  4643.  
  4644.           If the asynchronous operation could not be initiated,
  4645.           WSAAsyncGetHostByName() returns a zero value, and a specific
  4646.           error number may be retrieved by calling WSAGetLastError().
  4647.  
  4648. Comments  The buffer supplied to this function is used by the Windows
  4649.           Sockets implementation to construct a hostent structure
  4650.           together with the contents of data areas referenced by
  4651.           members of the same hostent structure.  To avoid the
  4652.           WSAENOBUFS error noted above, the application should provide
  4653.           a buffer of at least MAXGETHOSTSTRUCT bytes (as defined in
  4654.           winsock.h).
  4655.  
  4656. Notes For
  4657. Windows Sockets
  4658. Suppliers It is the responsibility of the Windows Sockets
  4659.           implementation to ensure that messages are successfully
  4660.           posted to the application.  If a PostMessage() operation
  4661.           fails, the Windows Sockets implementation must re-post that
  4662.           message as long as the window exists.
  4663.  
  4664.           Windows Sockets suppliers should use the WSAMAKEASYNCREPLY
  4665.           macro when constructing the lParam in the message.
  4666.  
  4667.  
  4668.  
  4669. 90 WSAAsyncGetHostByName
  4670.  
  4671. Error Codes    The following error codes may be set when an
  4672.           application window receives a message.  As described above,
  4673.           they may be extracted from the lParam in the reply message
  4674.           using the WSAGETASYNCERROR macro.
  4675.  
  4676.           WSAENETDOWN         The Windows Sockets implementation has
  4677.                               detected that the network subsystem has
  4678.                               failed.
  4679.  
  4680.           WSAENOBUFS          No/insufficient buffer space is
  4681.                               available
  4682.  
  4683.           WSAHOST_NOT_FOUND   Authoritative Answer Host not found.
  4684.  
  4685.           WSATRY_AGAIN        Non-Authoritative Host not found, or
  4686.                               SERVERFAIL.
  4687.  
  4688.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  4689.                               REFUSED, NOTIMP.
  4690.  
  4691.           WSANO_DATA          Valid name, no data record of requested
  4692.                               type.
  4693.  
  4694.           The following errors may occur at the time of the function
  4695.           call, and indicate that the asynchronous operation could not
  4696.           be initiated.
  4697.  
  4698.           WSANOTINITIALISED   A successful WSAStartup() must occur
  4699.                               before using this API.
  4700.  
  4701.           WSAENETDOWN         The Windows Sockets implementation has
  4702.                               detected that the network subsystem has
  4703.                               failed.
  4704.  
  4705.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  4706.                               in progress.
  4707.  
  4708.           WSAEWOULDBLOCK      The asynchronous operation cannot be
  4709.                               scheduled at this time due to resource
  4710.                               or other constraints within the Windows
  4711.                               Sockets implementation.
  4712.  
  4713. See Also  gethostbyname(), WSACancelAsyncRequest()
  4714.  
  4715.  
  4716.  
  4717.                                              WSAAsyncGetProtoByName 91
  4718.  
  4719. 4.3.3 WSAAsyncGetProtoByName()
  4720. Description    Get protocol information corresponding to a protocol
  4721.           name - asynchronous version.
  4722.  
  4723.           #include <winsock.h>
  4724.  
  4725.           HANDLE PASCAL FAR WSAAsyncGetProtoByName ( HWND hWnd,
  4726.           unsigned int wMsg,  const char FAR * name, char FAR * buf,
  4727.           int buflen );
  4728.  
  4729.  
  4730.           hWnd      The handle of the window which should receive a
  4731.                     message when the asynchronous request completes.
  4732.  
  4733.           wMsg      The message to be received when the asynchronous
  4734.                     request completes.
  4735.  
  4736.           name      A pointer to the protocol name to be resolved.
  4737.  
  4738.           buf       A pointer to the data area to receive the protoent
  4739.                     data.  Note that this must be larger than the size
  4740.                     of a protoent structure.  This is because the data
  4741.                     area supplied is used by the Windows Sockets
  4742.                     implementation to contain not only a protoent
  4743.                     structure but any and all of the data which is
  4744.                     referenced by members of the protoent structure.
  4745.                     It is recommended that you supply a buffer of
  4746.                     MAXGETHOSTSTRUCT bytes.
  4747.  
  4748.           buflen    The size of data area buf above.
  4749.  
  4750. Remarks   This function is an asynchronous version of
  4751.           getprotobyname(), and is used to retrieve the protocol name
  4752.           and number corresponding to a protocol name.  The Windows
  4753.           Sockets implementation initiates the operation and returns
  4754.           to the caller immediately, passing back an asynchronous task
  4755.           handle which the application may use to identify the
  4756.           operation.  When the operation is completed, the results (if
  4757.           any) are copied into the buffer provided by the caller and a
  4758.           message is sent to the application's window.
  4759.  
  4760.           When the asynchronous operation is complete the
  4761.           application's window hWnd receives message wMsg.  The wParam
  4762.           argument contains the asynchronous task handle as returned
  4763.           by the original function call.  The high 16 bits of lParam
  4764.           contain any error code.  The error code may be any error as
  4765.           defined in winsock.h.  An error code of zero indicates
  4766.           successful completion of the asynchronous operation.  On
  4767.           successful completion, the buffer supplied to the original
  4768.           function call contains a protoent structure.  To access the
  4769.           elements of this structure, the original buffer address
  4770.           should be cast to a protoent structure pointer and accessed
  4771.           as appropriate.
  4772.  
  4773.           Note that if the error code is WSAENOBUFS, it indicates that
  4774.           the size of the buffer specified by buflen in the original
  4775.           call was too small to contain all the resultant information.
  4776.  
  4777.  
  4778.  
  4779. 92 WSAAsyncGetProtoByName
  4780.  
  4781.           In this case, the low 16 bits of lParam contain the size of
  4782.           buffer required to supply ALL the requisite information.  If
  4783.           the application decides that the partial data is inadequate,
  4784.           it may reissue the WSAAsyncGetProtoByName() function call
  4785.           with a buffer large enough to receive all the desired
  4786.           information (i.e.  no smaller than the low 16 bits of
  4787.           lParam).
  4788.  
  4789.           The error code and buffer length should be extracted from
  4790.           the lParam using the macros  WSAGETASYNCERROR and
  4791.           WSAGETASYNCBUFLEN, defined in winsock.h as:
  4792.  
  4793.           #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  4794.           #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  4795.  
  4796.           The use of these macros will maximize the portability of the
  4797.           source code for the application.
  4798.  
  4799.  
  4800. Return Value   The return value specifies whether or not the
  4801.           asynchronous operation was successfully initiated.  Note
  4802.           that it does not imply success or failure of the operation
  4803.           itself.
  4804.  
  4805.           If the operation was successfully initiated,
  4806.           WSAAsyncGetProtoByName() returns a nonzero value of type
  4807.           HANDLE which is the asynchronous task handle for the
  4808.           request.  This value can be used in two ways.  It can be
  4809.           used to cancel the operation using WSACancelAsyncRequest().
  4810.           It can also be used to match up asynchronous operations and
  4811.           completion messages, by examining the wParam message
  4812.           argument.
  4813.  
  4814.           If the asynchronous operation could not be initiated,
  4815.           WSAAsyncGetProtoByName() returns a zero value, and a
  4816.           specific error number may be retrieved by calling
  4817.           WSAGetLastError().
  4818.  
  4819. Comments  The buffer supplied to this function is used by the Windows
  4820.           Sockets implementation to construct a protoent structure
  4821.           together with the contents of data areas referenced by
  4822.           members of the same protoent structure.  To avoid the
  4823.           WSAENOBUFS error noted above, the application should provide
  4824.           a buffer of at least MAXGETHOSTSTRUCT bytes (as defined in
  4825.           winsock.h).
  4826.  
  4827. Notes For
  4828. Windows Sockets
  4829. Suppliers It is the responsibility of the Windows Sockets
  4830.           implementation to ensure that messages are successfully
  4831.           posted to the application.  If a PostMessage() operation
  4832.           fails, the Windows Sockets implementation must re-post that
  4833.           message as long as the window exists.
  4834.  
  4835.           Windows Sockets suppliers should use the WSAMAKEASYNCREPLY
  4836.           macro when constructing the lParam in the message.
  4837.  
  4838.  
  4839.  
  4840.                                              WSAAsyncGetProtoByName 93
  4841.  
  4842. Error Codes    The following error codes may be set when an
  4843.           application window receives a message.  As described above,
  4844.           they may be extracted from the lParam in the reply message
  4845.           using the WSAGETASYNCERROR macro.
  4846.  
  4847.           WSAENETDOWN         The Windows Sockets implementation has
  4848.                               detected that the network subsystem has
  4849.                               failed.
  4850.  
  4851.           WSAENOBUFS          No/insufficient buffer space is
  4852.                               available
  4853.  
  4854.           WSAHOST_NOT_FOUND   Authoritative Answer Host not found.
  4855.  
  4856.           WSATRY_AGAIN        Non-Authoritative Host not found, or
  4857.                               SERVERFAIL.
  4858.  
  4859.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  4860.                               REFUSED, NOTIMP.
  4861.  
  4862.           WSANO_DATA          Valid name, no data record of requested
  4863.                               type.
  4864.  
  4865.           The following errors may occur at the time of the function
  4866.           call, and indicate that the asynchronous operation could not
  4867.           be initiated.
  4868.  
  4869.           WSANOTINITIALISED   A successful WSAStartup() must occur
  4870.                               before using this API.
  4871.  
  4872.           WSAENETDOWN         The Windows Sockets implementation has
  4873.                               detected that the network subsystem has
  4874.                               failed.
  4875.  
  4876.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  4877.                               in progress.
  4878.  
  4879.           WSAEWOULDBLOCK      The asynchronous operation cannot be
  4880.                               scheduled at this time due to resource
  4881.                               or other constraints within the Windows
  4882.                               Sockets implementation.
  4883.  
  4884. See Also  getprotobyname(), WSACancelAsyncRequest()
  4885.  
  4886.  
  4887.  
  4888. 94 WSAAsyncGetProtoByNumber
  4889.  
  4890. 4.3.4 WSAAsyncGetProtoByNumber()
  4891. Description    Get protocol information corresponding to a protocol
  4892.           number - asynchronous version.
  4893.  
  4894.           #include <winsock.h>
  4895.  
  4896.           HANDLE PASCAL FAR WSAAsyncGetProtoByNumber ( HWND hWnd,
  4897.           unsigned int wMsg,  int number, char FAR * buf, int buflen
  4898.           );
  4899.  
  4900.  
  4901.           hWnd      The handle of the window which should receive a
  4902.                     message when the asynchronous request completes.
  4903.  
  4904.           wMsg      The message to be received when the asynchronous
  4905.                     request completes.
  4906.  
  4907.           number    The protocol number to be resolved, in host byte
  4908.                     order.
  4909.  
  4910.           buf       A pointer to the data area to receive the protoent
  4911.                     data.  Note that this must be larger than the size
  4912.                     of a protoent structure.  This is because the data
  4913.                     area supplied is used by the Windows Sockets
  4914.                     implementation to contain not only a protoent
  4915.                     structure but any and all of the data which is
  4916.                     referenced by members of the protoent structure.
  4917.                     It is recommended that you supply a buffer of
  4918.                     MAXGETHOSTSTRUCT bytes.
  4919.  
  4920.           buflen    The size of data area buf above.
  4921.  
  4922. Remarks   This function is an asynchronous version of
  4923.           getprotobynumber(), and is used to retrieve the protocol
  4924.           name and number corresponding to a protocol number.  The
  4925.           Windows Sockets implementation initiates the operation and
  4926.           returns to the caller immediately, passing back an
  4927.           asynchronous task handle which the application may use to
  4928.           identify the operation.  When the operation is completed,
  4929.           the results (if any) are copied into the buffer provided by
  4930.           the caller and a message is sent to the application's
  4931.           window.
  4932.  
  4933.           When the asynchronous operation is complete the
  4934.           application's window hWnd receives message wMsg.  The wParam
  4935.           argument contains the asynchronous task handle as returned
  4936.           by the original function call.  The high 16 bits of lParam
  4937.           contain any error code.  The error code may be any error as
  4938.           defined in winsock.h.  An error code of zero indicates
  4939.           successful completion of the asynchronous operation.  On
  4940.           successful completion, the buffer supplied to the original
  4941.           function call contains a protoent structure.  To access the
  4942.           elements of this structure, the original buffer address
  4943.           should be cast to a protoent structure pointer and accessed
  4944.           as appropriate.
  4945.  
  4946.  
  4947.  
  4948.                                            WSAAsyncGetProtoByNumber 95
  4949.  
  4950.           Note that if the error code is WSAENOBUFS, it indicates that
  4951.           the size of the buffer specified by buflen in the original
  4952.           call was too small to contain all the resultant information.
  4953.           In this case, the low 16 bits of lParam contain the size of
  4954.           buffer required to supply ALL the requisite information.  If
  4955.           the application decides that the partial data is inadequate,
  4956.           it may reissue the WSAAsyncGetProtoByNumber() function call
  4957.           with a buffer large enough to receive all the desired
  4958.           information (i.e. no smaller than the low 16 bits of
  4959.           lParam).
  4960.  
  4961.           The error code and buffer length should be extracted from
  4962.           the lParam using the macros  WSAGETASYNCERROR and
  4963.           WSAGETASYNCBUFLEN, defined in winsock.h as:
  4964.  
  4965.           #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  4966.           #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  4967.  
  4968.           The use of these macros will maximize the portability of the
  4969.           source code for the application.
  4970.  
  4971.  
  4972. Return Value   The return value specifies whether or not the
  4973.           asynchronous operation was successfully initiated.  Note
  4974.           that it does not imply success or failure of the operation
  4975.           itself.
  4976.  
  4977.           If the operation was successfully initiated,
  4978.           WSAAsyncGetProtoByNumber() returns a nonzero value of type
  4979.           HANDLE which is the asynchronous task handle for the
  4980.           request.  This value can be used in two ways.  It can be
  4981.           used to cancel the operation using WSACancelAsyncRequest().
  4982.           It can also be used to match up asynchronous operations and
  4983.           completion messages, by examining the wParam message
  4984.           argument.
  4985.  
  4986.           If the asynchronous operation could not be initiated,
  4987.           WSAAsyncGetProtoByNumber() returns a zero value, and a
  4988.           specific error number may be retrieved by calling
  4989.           WSAGetLastError().
  4990.  
  4991. Comments  The buffer supplied to this function is used by the Windows
  4992.           Sockets implementation to construct a protoent structure
  4993.           together with the contents of data areas referenced by
  4994.           members of the same protoent structure.  To avoid the
  4995.           WSAENOBUFS error noted above, the application should provide
  4996.           a buffer of at least MAXGETHOSTSTRUCT bytes (as defined in
  4997.           winsock.h).
  4998.  
  4999. Notes For
  5000. Windows Sockets
  5001. Suppliers It is the responsibility of the Windows Sockets
  5002.           implementation to ensure that messages are successfully
  5003.           posted to the application.  If a PostMessage() operation
  5004.           fails, the Windows Sockets implementation must re-post that
  5005.           message as long as the window exists.
  5006.  
  5007.  
  5008.  
  5009. 96 WSAAsyncGetProtoByNumber
  5010.  
  5011.           Windows Sockets suppliers should use the WSAMAKEASYNCREPLY
  5012.           macro when constructing the lParam in the message.
  5013.  
  5014. Error Codes    The following error codes may be set when an
  5015.           application window receives a message.  As described above,
  5016.           they may be extracted from the lParam in the reply message
  5017.           using the WSAGETASYNCERROR macro.
  5018.  
  5019.           WSAENETDOWN         The Windows Sockets implementation has
  5020.                               detected that the network subsystem has
  5021.                               failed.
  5022.  
  5023.           WSAENOBUFS          No/insufficient buffer space is
  5024.                               available
  5025.  
  5026.           WSAHOST_NOT_FOUND   Authoritative Answer Host not found.
  5027.  
  5028.           WSATRY_AGAIN        Non-Authoritative Host not found, or
  5029.                               SERVERFAIL.
  5030.  
  5031.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  5032.                               REFUSED, NOTIMP.
  5033.  
  5034.           WSANO_DATA          Valid name, no data record of requested
  5035.                               type.
  5036.  
  5037.           The following errors may occur at the time of the function
  5038.           call, and indicate that the asynchronous operation could not
  5039.           be initiated.
  5040.  
  5041.           WSANOTINITIALISED   A successful WSAStartup() must occur
  5042.                               before using this API.
  5043.  
  5044.           WSAENETDOWN         The Windows Sockets implementation has
  5045.                               detected that the network subsystem has
  5046.                               failed.
  5047.  
  5048.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  5049.                               in progress.
  5050.  
  5051.           WSAEWOULDBLOCK      The asynchronous operation cannot be
  5052.                               scheduled at this time due to resource
  5053.                               or other constraints within the Windows
  5054.                               Sockets implementation.
  5055. See Also  getprotobynumber(), WSACancelAsyncRequest()
  5056.  
  5057.  
  5058.  
  5059.                                               WSAAsyncGetServByName 97
  5060.  
  5061. 4.3.5 WSAAsyncGetServByName()
  5062. Description    Get service information corresponding to a service name
  5063.           and port - asynchronous version.
  5064.  
  5065.           #include <winsock.h>
  5066.  
  5067.           HANDLE PASCAL FAR WSAAsyncGetServByName ( HWND hWnd,
  5068.           unsigned int wMsg,  const char FAR * name, const char FAR *
  5069.           proto, char FAR * buf,  int buflen );
  5070.  
  5071.  
  5072.           hWnd      The handle of the window which should receive a
  5073.                     message when the asynchronous request completes.
  5074.  
  5075.           wMsg      The message to be received when the asynchronous
  5076.                     request completes.
  5077.  
  5078.           name      A pointer to a service name.
  5079.  
  5080.           proto     A pointer to a protocol name.  This may be NULL,
  5081.                     in which case WSAAsyncGetServByName() will search
  5082.                     for the first service entry for which s_name or
  5083.                     one of the s_aliases matches the given name.
  5084.                     Otherwise WSAAsyncGetServByName() matches both
  5085.                     name and proto.
  5086.  
  5087.           buf       A pointer to the data area to receive the servent
  5088.                     data.  Note that this must be larger than the size
  5089.                     of a servent structure.  This is because the data
  5090.                     area supplied is used by the Windows Sockets
  5091.                     implementation to contain not only a servent
  5092.                     structure but any and all of the data which is
  5093.                     referenced by members of the servent structure.
  5094.                     It is recommended that you supply a buffer of
  5095.                     MAXGETHOSTSTRUCT bytes.
  5096.  
  5097.           buflen    The size of data area buf above.
  5098.  
  5099. Remarks   This function is an asynchronous version of getservbyname(),
  5100.           and is used to retrieve service information corresponding to
  5101.           a service name.  The Windows Sockets implementation
  5102.           initiates the operation and returns to the caller
  5103.           immediately, passing back an asynchronous task handle which
  5104.           the application may use to identify the operation.  When the
  5105.           operation is completed, the results (if any) are copied into
  5106.           the buffer provided by the caller and a message is sent to
  5107.           the application's window.
  5108.  
  5109.           When the asynchronous operation is complete the
  5110.           application's window hWnd receives message wMsg.  The wParam
  5111.           argument contains the asynchronous task handle as returned
  5112.           by the original function call.  The high 16 bits of lParam
  5113.           contain any error code.  The error code may be any error as
  5114.           defined in winsock.h.  An error code of zero indicates
  5115.           successful completion of the asynchronous operation.  On
  5116.           successful completion, the buffer supplied to the original
  5117.           function call contains a hostent structure.  To access the
  5118.  
  5119.  
  5120.  
  5121. 98 WSAAsyncGetServByName
  5122.  
  5123.           elements of this structure, the original buffer address
  5124.           should be cast to a hostent structure pointer and accessed
  5125.           as appropriate.
  5126.  
  5127.           Note that if the error code is WSAENOBUFS, it indicates that
  5128.           the size of the buffer specified by buflen in the original
  5129.           call was too small to contain all the resultant information.
  5130.           In this case, the low 16 bits of lParam contain the size of
  5131.           buffer required to supply ALL the requisite information.  If
  5132.           the application decides that the partial data is inadequate,
  5133.           it may reissue the WSAAsyncGetServByName() function call
  5134.           with a buffer large enough to receive all the desired
  5135.           information (i.e. no smaller than the low 16 bits of
  5136.           lParam).
  5137.  
  5138.           The error code and buffer length should be extracted from
  5139.           the lParam using the macros  WSAGETASYNCERROR and
  5140.           WSAGETASYNCBUFLEN, defined in winsock.h as:
  5141.  
  5142.           #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  5143.           #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  5144.  
  5145.           The use of these macros will maximize the portability of the
  5146.           source code for the application.
  5147.  
  5148.  
  5149. Return Value   The return value specifies whether or not the
  5150.           asynchronous operation was successfully initiated.  Note
  5151.           that it does not imply success or failure of the operation
  5152.           itself.
  5153.  
  5154.           If the operation was successfully initiated,
  5155.           WSAAsyncGetServByName() returns a nonzero value of type
  5156.           HANDLE which is the asynchronous task handle for the
  5157.           request.  This value can be used in two ways.  It can be
  5158.           used to cancel the operation using WSACancelAsyncRequest().
  5159.           It can also be used to match up asynchronous operations and
  5160.           completion messages, by examining the wParam message
  5161.           argument.
  5162.  
  5163.           If the asynchronous operation could not be initiated,
  5164.           WSAAsyncServByName() returns a zero value, and a specific
  5165.           error number may be retrieved by calling WSAGetLastError().
  5166.  
  5167. Comments  The buffer supplied to this function is used by the Windows
  5168.           Sockets implementation to construct a hostent structure
  5169.           together with the contents of data areas referenced by
  5170.           members of the same hostent structure.  To avoid the
  5171.           WSAENOBUFS error noted above, the application should provide
  5172.           a buffer of at least MAXGETHOSTSTRUCT bytes (as defined in
  5173.           winsock.h).
  5174.  
  5175. Notes For
  5176. Windows Sockets
  5177. Suppliers It is the responsibility of the Windows Sockets
  5178.           implementation to ensure that messages are successfully
  5179.           posted to the application.  If a PostMessage() operation
  5180.  
  5181.  
  5182.  
  5183.                                               WSAAsyncGetServByName 99
  5184.  
  5185.           fails, the Windows Sockets implementation must re-post that
  5186.           message as long as the window exists.
  5187.  
  5188.           Windows Sockets suppliers should use the WSAMAKEASYNCREPLY
  5189.           macro when constructing the lParam in the message.
  5190.  
  5191. Error Codes    The following error codes may be set when an
  5192.           application window receives a message.  As described above,
  5193.           they may be extracted from the lParam in the reply message
  5194.           using the WSAGETASYNCERROR macro.
  5195.  
  5196.           WSAENETDOWN         The Windows Sockets implementation has
  5197.                               detected that the network subsystem has
  5198.                               failed.
  5199.  
  5200.           WSAENOBUFS          No/insufficient buffer space is
  5201.                               available
  5202.  
  5203.           WSAHOST_NOT_FOUND   Authoritative Answer Host not found.
  5204.  
  5205.           WSATRY_AGAIN        Non-Authoritative Host not found, or
  5206.                               SERVERFAIL.
  5207.  
  5208.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  5209.                               REFUSED, NOTIMP.
  5210.  
  5211.           WSANO_DATA          Valid name, no data record of requested
  5212.                               type.
  5213.  
  5214.           The following errors may occur at the time of the function
  5215.           call, and indicate that the asynchronous operation could not
  5216.           be initiated.
  5217.  
  5218.           WSANOTINITIALISED   A successful WSAStartup() must occur
  5219.                               before using this API.
  5220.  
  5221.           WSAENETDOWN         The Windows Sockets implementation has
  5222.                               detected that the network subsystem has
  5223.                               failed.
  5224.  
  5225.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  5226.                               in progress.
  5227.  
  5228.           WSAEWOULDBLOCK      The asynchronous operation cannot be
  5229.                               scheduled at this time due to resource
  5230.                               or other constraints within the Windows
  5231.                               Sockets implementation.
  5232.  
  5233. See Also  getservbyname(), WSACancelAsyncRequest()
  5234.  
  5235.  
  5236.  
  5237. 100 WSAAsyncGetServByPort
  5238.  
  5239. 4.3.6 WSAAsyncGetServByPort()
  5240. Description    Get service information corresponding to a port and
  5241.           protocol - asynchronous version.
  5242.  
  5243.           #include <winsock.h>
  5244.  
  5245.           HANDLE PASCAL FAR WSAAsyncGetServByPort ( HWND hWnd,
  5246.           unsigned int wMsg,  int port, const char FAR * proto, char
  5247.           FAR * buf, int buflen );
  5248.  
  5249.  
  5250.           hWnd      The handle of the window which should receive a
  5251.                     message when the asynchronous request completes.
  5252.  
  5253.           wMsg      The message to be received when the asynchronous
  5254.                     request completes.
  5255.  
  5256.           port      The port for the service, in network byte order.
  5257.  
  5258.           proto     A pointer to a protocol name.  This may be NULL,
  5259.                     in which case WSAAsyncGetServByPort() will search
  5260.                     for the first service entry for which s_port match
  5261.                     the given port.  Otherwise WSAAsyncGetServByPort()
  5262.                     matches both port and proto.
  5263.  
  5264.           buf       A pointer to the data area to receive the servent
  5265.                     data.  Note that this must be larger than the size
  5266.                     of a servent structure.  This is because the data
  5267.                     area supplied is used by the Windows Sockets
  5268.                     implementation to contain not only a servent
  5269.                     structure but any and all of the data which is
  5270.                     referenced by members of the servent structure.
  5271.                     It is recommended that you supply a buffer of
  5272.                     MAXGETHOSTSTRUCT bytes.
  5273.  
  5274.           buflen    The size of data area buf above.
  5275.  
  5276. Remarks   This function is an asynchronous version of getservbyport(),
  5277.           and is used to retrieve service information corresponding to
  5278.           a port number.  The Windows Sockets implementation initiates
  5279.           the operation and returns to the caller immediately, passing
  5280.           back an asynchronous task handle which the application may
  5281.           use to identify the operation.  When the operation is
  5282.           completed, the results (if any) are copied into the buffer
  5283.           provided by the caller and a message is sent to the
  5284.           application's window.
  5285.  
  5286.           When the asynchronous operation is complete the
  5287.           application's window hWnd receives message wMsg.  The wParam
  5288.           argument contains the asynchronous task handle as returned
  5289.           by the original function call.  The high 16 bits of lParam
  5290.           contain any error code.  The error code may be any error as
  5291.           defined in winsock.h.  An error code of zero indicates
  5292.           successful completion of the asynchronous operation.  On
  5293.           successful completion, the buffer supplied to the original
  5294.           function call contains a servent structure.  To access the
  5295.           elements of this structure, the original buffer address
  5296.  
  5297.  
  5298.  
  5299.                                              WSAAsyncGetServByPort 101
  5300.  
  5301.           should be cast to a servent structure pointer and accessed
  5302.           as appropriate.
  5303.  
  5304.           Note that if the error code is WSAENOBUFS, it indicates that
  5305.           the size of the buffer specified by buflen in the original
  5306.           call was too small to contain all the resultant information.
  5307.           In this case, the low 16 bits of lParam contain the size of
  5308.           buffer required to supply ALL the requisite information.  If
  5309.           the application decides that the partial data is inadequate,
  5310.           it may reissue the WSAAsyncGetServByPort() function call
  5311.           with a buffer large enough to receive all the desired
  5312.           information (i.e. no smaller than the low 16 bits of
  5313.           lParam).
  5314.  
  5315.           The error code and buffer length should be extracted from
  5316.           the lParam using the macros  WSAGETASYNCERROR and
  5317.           WSAGETASYNCBUFLEN, defined in winsock.h as:
  5318.  
  5319.           #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  5320.           #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  5321.  
  5322.           The use of these macros will maximize the portability of the
  5323.           source code for the application.
  5324.  
  5325.  
  5326. Return Value   The return value specifies whether or not the
  5327.           asynchronous operation was successfully initiated.  Note
  5328.           that it does not imply success or failure of the operation
  5329.           itself.
  5330.  
  5331.           If the operation was successfully initiated,
  5332.           WSAAsyncGetServByPort() returns a nonzero value of type
  5333.           HANDLE which is the asynchronous task handle for the
  5334.           request.  This value can be used in two ways.  It can be
  5335.           used to cancel the operation using WSACancelAsyncRequest().
  5336.           It can also be used to match up asynchronous operations and
  5337.           completion messages, by examining the wParam message
  5338.           argument.
  5339.  
  5340.           If the asynchronous operation could not be initiated,
  5341.           WSAAsyncGetServByPort() returns a zero value, and a specific
  5342.           error number may be retrieved by calling WSAGetLastError().
  5343.  
  5344. Comments  The buffer supplied to this function is used by the Windows
  5345.           Sockets implementation to construct a servent structure
  5346.           together with the contents of data areas referenced by
  5347.           members of the same servent structure.  To avoid the
  5348.           WSAENOBUFS error noted above, the application should provide
  5349.           a buffer of at least MAXGETHOSTSTRUCT bytes (as defined in
  5350.           winsock.h).
  5351.  
  5352. Notes For
  5353. Windows Sockets
  5354. Suppliers It is the responsibility of the Windows Sockets
  5355.           implementation to ensure that messages are successfully
  5356.           posted to the application.  If a PostMessage() operation
  5357.  
  5358.  
  5359.  
  5360. 102 WSAAsyncGetServByPort
  5361.  
  5362.           fails, the Windows Sockets implementation must re-post that
  5363.           message as long as the window exists.
  5364.  
  5365.           Windows Sockets suppliers should use the WSAMAKEASYNCREPLY
  5366.           macro when constructing the lParam in the message.
  5367.  
  5368. Error Codes    The following error codes may be set when an
  5369.           application window receives a message.  As described above,
  5370.           they may be extracted from the lParam in the reply message
  5371.           using the WSAGETASYNCERROR macro.
  5372.  
  5373.           WSAENETDOWN         The Windows Sockets implementation has
  5374.                               detected that the network subsystem has
  5375.                               failed.
  5376.  
  5377.           WSAENOBUFS          No/insufficient buffer space is
  5378.                               available
  5379.  
  5380.           WSAHOST_NOT_FOUND   Authoritative Answer Host not found.
  5381.  
  5382.           WSATRY_AGAIN        Non-Authoritative Host not found, or
  5383.                               SERVERFAIL.
  5384.  
  5385.           WSANO_RECOVERY      Non recoverable errors, FORMERR,
  5386.                               REFUSED, NOTIMP.
  5387.  
  5388.           WSANO_DATA          Valid name, no data record of requested
  5389.                               type.
  5390.  
  5391.           The following errors may occur at the time of the function
  5392.           call, and indicate that the asynchronous operation could not
  5393.           be initiated.
  5394.  
  5395.           WSANOTINITIALISED   A successful WSAStartup() must occur
  5396.                               before using this API.
  5397.  
  5398.           WSAENETDOWN         The Windows Sockets implementation has
  5399.                               detected that the network subsystem has
  5400.                               failed.
  5401.  
  5402.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  5403.                               in progress.
  5404.  
  5405.           WSAEWOULDBLOCK      The asynchronous operation cannot be
  5406.                               scheduled at this time due to resource
  5407.                               or other constraints within the Windows
  5408.                               Sockets implementation.
  5409.  
  5410. See Also  getservbyport(), WSACancelAsyncRequest()
  5411.  
  5412.  
  5413.  
  5414.                                                     WSAAsyncSelect 103
  5415.  
  5416. 4.3.7 WSAAsyncSelect()
  5417. Description    Request event notification for a socket.
  5418.  
  5419.           #include <winsock.h>
  5420.  
  5421.           int PASCAL FAR WSAAsyncSelect ( SOCKET s, HWND hWnd,
  5422.           unsigned int wMsg,  long lEvent );
  5423.  
  5424.  
  5425.           s         A descriptor identifying the socket for which
  5426.                     event notification is required.
  5427.  
  5428.           hWnd      A handle identifying the window which should
  5429.                     receive a message when a network event occurs.
  5430.  
  5431.           wMsg      The message to be received when a network event
  5432.                     occurs.
  5433.  
  5434.           lEvent    A bitmask which specifies a combination of network
  5435.                     events in which the application is interested.
  5436.  
  5437. Remarks   This function is used to request that the Windows Sockets
  5438.           DLL should send a message to the window hWnd whenever it
  5439.           detects any of the network events specified by the lEvent
  5440.           parameter.  The message which should be sent is specified by
  5441.           the wMsg parameter.  The socket for which notification is
  5442.           required is identified by s.
  5443.  
  5444.           This function automatically sets socket s to non-blocking
  5445.           mode.
  5446.  
  5447.           The lEvent parameter is constructed by or'ing any of the
  5448.           values specified in the following list.
  5449.  
  5450.                Value     Meaning
  5451.                FD_READ   Want to receive notification of readiness for
  5452.                          reading
  5453.                FD_WRITE  Want to receive notification of readiness for
  5454.                          writing
  5455.                FD_OOB    Want to receive notification of the arrival
  5456.                          of out-of-band data
  5457.                FD_ACCEPT Want to receive notification of incoming
  5458.                          connections
  5459.                FD_CONNECT     Want to receive notification of
  5460.                          completed connection
  5461.                FD_CLOSE  Want to receive notification of socket
  5462.                          closure
  5463.  
  5464.           Issuing a WSAAsyncSelect() for a socket cancels any previous
  5465.           WSAAsyncSelect() for the same socket.  For example, to
  5466.           receive notification for both reading and writing, the
  5467.           application must call WSAAsyncSelect() with both FD_READ and
  5468.           FD_WRITE, as follows:
  5469.  
  5470.           rc = WSAAsyncSelect(s, hWnd, wMsg, FD_READ|FD_WRITE);
  5471.  
  5472.  
  5473.  
  5474. 104 WSAAsyncSelect
  5475.  
  5476.           It is not possible to specify different messages for
  5477.           different events.  The following code will not work; the
  5478.           second call will cancel the effects of the first, and only
  5479.           FD_WRITE events will be reported with message wMsg2:
  5480.  
  5481.           rc = WSAAsyncSelect(s, hWnd, wMsg1, FD_READ);
  5482.           rc = WSAAsyncSelect(s, hWnd, wMsg2, FD_WRITE);
  5483.  
  5484.           To cancel all notification  i.e., to indicate that the
  5485.           Windows Sockets implementation should send no further
  5486.           messages related to network events on the socket  lEvent
  5487.           should be set to zero.
  5488.  
  5489.           rc = WSAAsyncSelect(s, hWnd, 0, 0);
  5490.  
  5491.           Although in this instance WSAAsyncSelect() immediately
  5492.           disables event message posting for the socket, it is
  5493.           possible that messages may be waiting in the application's
  5494.           message queue.  The application must therefore be prepared
  5495.           to receive network event messages even after cancellation.
  5496.           Closing a socket with closesocket() also cancels
  5497.           WSAAsyncSelect() message sending, but the same caveat about
  5498.           messages in the queue prior to the closesocket() still
  5499.           applies.
  5500.  
  5501.           Since an accept()'ed socket has the same properties as the
  5502.           listening socket used to accept it, any WSAAsyncSelect()
  5503.           events set for the listening socket apply to the accepted
  5504.           socket.  For example, if a listening socket has
  5505.           WSAAsyncSelect() events FD_ACCEPT, FD_READ, and FD_WRITE,
  5506.           then any socket accepted on that listening socket will also
  5507.           have FD_ACCEPT, FD_READ, and FD_WRITE events with the same
  5508.           wMsg value used for messages.  If a different wMsg or events
  5509.           are desired, the application should call WSAAsyncSelect(),
  5510.           passing the accepted socket and the desired new
  5511.           information.7
  5512.  
  5513.           When one of the nominated network events occurs on the
  5514.           specified socket s, the application's window hWnd receives
  5515.           message wMsg.  The wParam argument identifies the socket on
  5516.           which a network event has occurred.  The low word of lParam
  5517.           specifies the network event that has occurred.  The high
  5518.           word of lParam contains any error code.  The error code be
  5519.           any error as defined in winsock.h.
  5520.  
  5521.           The error and event codes may be extracted from the lParam
  5522.           using the macros WSAGETSELECTERROR and WSAGETSELECTEVENT,
  5523.           defined in winsock.h as:
  5524.                     
  5525. 7Note that there is a timing window between the accept() 
  5526.                                                 accept() 
  5527.                                                 accept() call and the
  5528. call to WSAAsyncSelect() 
  5529.         WSAAsyncSelect() 
  5530.         WSAAsyncSelect() to change the events or wMsg.  An application
  5531. which desires a different wMsg for the listening and accept()
  5532.                                                      accept()
  5533.                                                      accept()'ed
  5534. sockets should ask for only FD_ACCEPT events on the listening socket,
  5535. then set appropriate events after the accept()
  5536.                                       accept()
  5537.                                       accept().  Since FD_ACCEPT is
  5538. never sent for a connected socket and FD_READ, FD_WRITE, FD_OOB, and
  5539. FD_CLOSE are never sent for listening sockets, this will not impose
  5540. difficulties.
  5541.  
  5542.  
  5543.  
  5544.                                                     WSAAsyncSelect 105
  5545.  
  5546.  
  5547.           #define WSAGETSELECTERROR(lParam)            HIWORD(lParam)
  5548.           #define WSAGETSELECTEVENT(lParam)            LOWORD(lParam)
  5549.  
  5550.           The use of these macros will maximize the portability of the
  5551.           source code for the application.
  5552.  
  5553.           The possible network event codes which may be returned are
  5554.           as follows:
  5555.  
  5556.                Value     Meaning
  5557.                FD_READ   Socket s ready for reading
  5558.                FD_WRITE  Socket s ready for writing
  5559.                FD_OOB    Out-of-band data ready for reading on socket
  5560.                          s.
  5561.                FD_ACCEPT Socket s ready for accepting a new incoming
  5562.                          connection
  5563.                FD_CONNECT     Connection on socket s completed
  5564.                FD_CLOSE  Connection identified by socket s has been
  5565.                          closed
  5566.  
  5567.  
  5568. Return Value   The return value is 0 if the application's declaration
  5569.           of interest in the network event set was successful.
  5570.           Otherwise the value SOCKET_ERROR is returned, and a specific
  5571.           error number may be retrieved by calling WSAGetLastError().
  5572.  
  5573. Comments  Although WSAAsyncSelect() can be called with interest in
  5574.           multiple events, the application window will receive a
  5575.           single message for each network event.
  5576.  
  5577.           As in the case of the select() function, WSAAsyncSelect()
  5578.           will frequently be used to determine when a data transfer
  5579.           operation (send() or recv()) can be issued with the
  5580.           expectation of immediate success.  Nevertheless, a robust
  5581.           application must be prepared for the possibility that it may
  5582.           receive a message and issue a Windows Sockets API call which
  5583.           returns WSAEWOULDBLOCK immediately.  For example, the
  5584.           following sequence of events is possible:
  5585.  
  5586.           (i)       data arrives on socket s; Windows Sockets posts
  5587.                     WSAAsyncSelect message
  5588.           (ii)      application processes some other message
  5589.           (iii)     while processing, application issues an
  5590.                     ioctlsocket(s, FIONREAD...) and notices that there
  5591.                     is data ready to be read
  5592.           (iv)      application issues a recv(s,...) to read the data
  5593.           (v)       application  loops to process next message,
  5594.                     eventually reaching the WSAAsyncSelect message
  5595.                     indicating that data is ready to read
  5596.           (vi)      application issues recv(s,...), which fails with
  5597.                     the error WSAEWOULDBLOCK.
  5598.  
  5599.           Other sequences are possible.
  5600.  
  5601.           The Windows Sockets DLL will not continually flood an
  5602.           application with messages for a particular network event.
  5603.  
  5604.  
  5605.  
  5606. 106 WSAAsyncSelect
  5607.  
  5608.           Having successfully posted notification of a particular
  5609.           event to an application window, no further message(s) for
  5610.           that network event will be posted to the application window
  5611.           until the application makes the function call which
  5612.           implicitly reenables notification of that network event.
  5613.  
  5614.           Event          Re-enabling function
  5615.           FD_READ        recv() or recvfrom()
  5616.           FD_WRITE       send() or sendto()
  5617.           FD_OOB         recv()
  5618.           FD_ACCEPT      accept()
  5619.           FD_CONNECT     NONE
  5620.           FD_CLOSE       NONE
  5621.  
  5622.           Any call to the reenabling routine, even one which fails,
  5623.           results in reenabling of message posting for the relevant
  5624.           event.
  5625.  
  5626.           For FD_READ, FD_OOB, and FD_ACCEPT events, message posting
  5627.           is "level-triggered."  This means that if the reenabling
  5628.           routine is called and the relevant event is still valid
  5629.           after the call, a WSAAsyncSelect() message is posted to the
  5630.           application.  This allows an application to be event-driven
  5631.           and not concern itself with the amount of data that arrives
  5632.           at any one time.  Consider the following sequence:
  5633.  
  5634.           (i)       Windows Sockets DLL receives 100 bytes of data on
  5635.                     socket s and posts an FD_READ message.
  5636.           (ii)      The application issues recv( s, buffptr, 50, 0) to
  5637.                     read 50 bytes.
  5638.           (iii)     The Windows Sockets DLL posts another FD_READ
  5639.                     message since there is still data to be read.
  5640.  
  5641.           With these semantics, an application need not read all
  5642.           available data in response to an FD_READ message--a single
  5643.           recv() in response to each FD_READ message is appropriate.
  5644.           If an application issues multiple recv() calls in response
  5645.           to a single FD_READ, it may receive multiple FD_READ
  5646.           messages.  Such an application may wish to disable FD_READ
  5647.           messages before starting the recv() calls by calling
  5648.           WSAAsyncSelect() with the FD_READ event not set.
  5649.  
  5650.           If an event is true when the application initially calls
  5651.           WSAAsyncSelect() or when the reenabling function is called,
  5652.           then a message is posted as appropriate.  For example, if an
  5653.           application calls listen(), a connect attempt is made, then
  5654.           the application calls WSAAsyncSelect() specifying that it
  5655.           wants to receive FD_ACCEPT messages for the socket, the
  5656.           Windows Sockets implementation posts an FD_ACCEPT message
  5657.           immediately.
  5658.  
  5659.           The FD_WRITE event is handled slightly differently.  An
  5660.           FD_WRITE message is posted when a socket is first connected
  5661.           with connect() or accepted with accept(), and then after a
  5662.           send() or sendto() fails with WSAEWOULDBLOCK and buffer
  5663.           space becomes available.  Therefore, an application can
  5664.           assume that sends are possible starting from the first
  5665.  
  5666.  
  5667.  
  5668.                                                     WSAAsyncSelect 107
  5669.  
  5670.           FD_WRITE message and lasting until a send returns
  5671.           WSAEWOULDBLOCK.  After such a failure the application will
  5672.           be notified that sends are again possible with an FD_WRITE
  5673.           message.
  5674.  
  5675.           The FD_OOB event is used only when a socket is configured to
  5676.           receive out-of-band data separately.  If the socket is
  5677.           configured to receive out-of-band data in-line, the out-of-
  5678.           band (expedited) data is treated as normal data and the
  5679.           application should register an interest in, and will
  5680.           receive, FD_READ events, not FD_OOB events.  An application
  5681.           may set or inspect the way in which out-of-band data is to
  5682.           be handled by using setsockopt() or getsockopt() for the
  5683.           SO_OOBINLINE option.
  5684.  
  5685.           The error code in an FD_CLOSE message indicates whether the
  5686.           socket close was graceful or abortive.  If the error code is
  5687.           0, then the close was graceful; if the error code is
  5688.           WSAECONNRESET, then the socket's virtual socket was reset.
  5689.           This only applies to sockets of type SOCK_STREAM.
  5690.  
  5691.           The FD_CLOSE message is posted when a close indication is
  5692.           received for the virtual circuit corresponding to the
  5693.           socket.  In TCP terms, this means that the FD_CLOSE is
  5694.           posted when the connection goes into the FIN WAIT or CLOSE
  5695.           WAIT states.  This results from the remote end performing a
  5696.           shutdown() on the send side or a closesocket().
  5697.  
  5698.           Please note your application will receive ONLY an FD_CLOSE
  5699.           message to indicate closure of a virtual circuit. It will
  5700.           NOT receive an FD_READ message to indicate this condition.
  5701.  
  5702. Error Codes                   WSANOTINITIALISED   A successful
  5703.                               WSAStartup() must occur before using
  5704.                               this API.
  5705.  
  5706.           WSAENETDOWN         The Windows Sockets implementation has
  5707.                               detected that the network subsystem has
  5708.                               failed.
  5709.  
  5710.           WSAEINVAL           Indicates that one of the specified
  5711.                               parameters was invalid
  5712.  
  5713.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  5714.                               in progress.
  5715.  
  5716.           Additional error codes may be set when an application window
  5717.           receives a message.  This error code is extracted from the
  5718.           lParam in the reply message using the WSAGETSELECTERROR
  5719.           macro.  Possible error codes for each network event are:
  5720.           Event: FD_CONNECT
  5721.           Error Code          Meaning
  5722.           WSAEADDRINUSE       The specified address is already in use.
  5723.  
  5724.           WSAEADDRNOTAVAIL    The specified address is not available
  5725.                               from the local machine.
  5726.  
  5727.  
  5728.  
  5729. 108 WSAAsyncSelect
  5730.  
  5731.           WSAEAFNOSUPPORT     Addresses in the specified family cannot
  5732.                               be used with this socket.
  5733.  
  5734.           WSAECONNREFUSED     The attempt to connect was forcefully
  5735.                               rejected.
  5736.  
  5737.           WSAEDESTADDRREQ     A destination address is required.
  5738.  
  5739.           WSAEFAULT           The namelen argument is incorrect.
  5740.  
  5741.           WSAEINVAL           The socket is already bound to an
  5742.                               address.
  5743.  
  5744.           WSAEISCONN          The socket is already connected.
  5745.  
  5746.           WSAEMFILE           No more file descriptors are available.
  5747.  
  5748.           WSAENETUNREACH      The network can't be reached from this
  5749.                               host at this time.
  5750.  
  5751.           WSAENOBUFS          No buffer space is available.  The
  5752.                               socket cannot be connected.
  5753.  
  5754.           WSAENOTCONN         The socket is not connected.
  5755.  
  5756.           WSAENOTSOCK         The descriptor is a file, not a socket.
  5757.  
  5758.           WSAETIMEDOUT        Attempt to connect timed out without
  5759.                               establishing a connection
  5760.  
  5761.           Event: FD_CLOSE
  5762.           Error Code          Meaning
  5763.           WSAENETDOWN         The Windows Sockets implementation has
  5764.                               detected that the network subsystem has
  5765.                               failed.
  5766.  
  5767.           WSAECONNRESET       The connection was reset by the remote
  5768.                               side.
  5769.  
  5770.           WSAECONNABORTED     The connection was aborted due to
  5771.                               timeout or other failure.
  5772.  
  5773.           Event: FD_READ
  5774.           Event: FD_WRITE
  5775.           Event: FD_OOB
  5776.           Event: FD_ACCEPT
  5777.           Error Code          Meaning
  5778.           WSAENETDOWN         The Windows Sockets implementation has
  5779.                               detected that the network subsystem has
  5780.                               failed.
  5781.  
  5782. Notes For
  5783. Windows Sockets
  5784. Suppliers It is the responsibility of the Windows Sockets Supplier to
  5785.           ensure that messages are successfully posted to the
  5786.           application.  If a PostMessage() operation fails, the
  5787.  
  5788.  
  5789.  
  5790.                                                     WSAAsyncSelect 109
  5791.  
  5792.           Windows Sockets implementation MUST re-post that message as
  5793.           long as the window exists.
  5794.  
  5795.           Windows Sockets suppliers should use the WSAMAKESELECTREPLY
  5796.           macro when constructing the lParam in the message.
  5797.  
  5798.           When a socket is closed, the Windows Sockets Supplier should
  5799.           purge any messages remaining for posting to the application
  5800.           window.  However the application must be prepared to
  5801.           receive, and discard, any messages which may have been
  5802.           posted prior to the closesocket().
  5803.  
  5804. See Also  select()
  5805.  
  5806.  
  5807.  
  5808. 110 WSACancelAsyncRequest
  5809.  
  5810. 4.3.8 WSACancelAsyncRequest()
  5811. Description    Cancel an incomplete asynchronous operation.
  5812.  
  5813.           #include <winsock.h>
  5814.  
  5815.           int PASCAL FAR WSACancelAsyncRequest ( HANDLE
  5816.           hAsyncTaskHandle );
  5817.  
  5818.  
  5819.           hAsyncTaskHandle    Specifies the asynchronous operation to
  5820.                     be canceled.
  5821.  
  5822. Remarks   The WSACancelAsyncRequest() function is used to cancel an
  5823.           asynchronous operation which was initiated by one of the
  5824.           WSAAsyncGetXByY() functions such as WSAAsyncGetHostByName().
  5825.           The operation to be canceled is identified by the
  5826.           hAsyncTaskHandle parameter, which should be set to the
  5827.           asynchronous task handle as returned by the initiating
  5828.           function.
  5829.  
  5830.  
  5831. Return Value   The value returned by WSACancelAsyncRequest() is 0 if
  5832.           the operation was successfully canceled.  Otherwise the
  5833.           value SOCKET_ERROR is returned, and a specific error number
  5834.           may be retrieved by calling WSAGetLastError().
  5835.  
  5836. Comments  An attempt to cancel an existing asynchronous
  5837.           WSAAsyncGetXByY() operation can fail with an error code of
  5838.           WSAEALREADY for two reasons.  First, the original operation
  5839.           has already completed and the application has dealt with the
  5840.           resultant message.  Second, the original operation has
  5841.           already completed but the resultant message is still waiting
  5842.           in the application window queue.
  5843.  
  5844. Notes For
  5845. Windows Sockets
  5846. Suppliers It is unclear whether the application can usefully
  5847.           distinguish between WSAEINVAL and WSAEALREADY, since in both
  5848.           cases the error indicates that there is no asynchronous
  5849.           operation in progress with the indicated handle.  [Trivial
  5850.           exception: 0 is always an invalid asynchronous task handle.]
  5851.           The Windows Sockets specification does not prescribe how a
  5852.           conformant Windows Sockets implementation should distinguish
  5853.           between the two cases.  For maximum portability, a Windows
  5854.           Sockets application should treat the two errors as
  5855.           equivalent.
  5856.  
  5857. Error Codes                   WSANOTINITIALISED   A successful
  5858.                               WSAStartup() must occur before using
  5859.                               this API.
  5860.  
  5861.           WSAENETDOWN         The Windows Sockets implementation has
  5862.                               detected that the network subsystem has
  5863.                               failed.
  5864.  
  5865.           WSAEINVAL           Indicates that the specified
  5866.                               asynchronous task handle was invalid
  5867.  
  5868.  
  5869.  
  5870.                                              WSACancelAsyncRequest 111
  5871.  
  5872.  
  5873.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  5874.                               in progress.
  5875.  
  5876.           WSAEALREADY         The asynchronous routine being canceled
  5877.                               has already completed.
  5878.  
  5879.  
  5880. See Also  WSAAsyncGetHostByAddr(), WSAAsyncGetHostByName(),
  5881.           WSAAsyncGetProtoByNumber(), WSAAsyncGetProtoByName(),
  5882.           WSAAsyncGetHostByName(), WSAAsyncGetServByPort(),
  5883.           WSAAsyncGetServByName().
  5884.  
  5885.  
  5886.  
  5887. 112 WSACancelBlockingCall
  5888.  
  5889. 4.3.9 WSACancelBlockingCall()
  5890. Description    Cancel a blocking call which is currently in progress.
  5891.  
  5892.           #include <winsock.h>
  5893.  
  5894.           int PASCAL FAR WSACancelBlockingCall ( void );
  5895.  
  5896. Remarks   This function cancels any outstanding blocking operation for
  5897.           this task.  It is normally used in two situations:
  5898.  
  5899.           (1) An application is processing a message which has been
  5900.           received while a blocking call is in progress.  In this
  5901.           case, WSAIsBlocking() will be true.
  5902.  
  5903.           (2) A blocking call is in progress, and Windows Sockets has
  5904.           called back to the application's "blocking hook" function
  5905.           (as established by WSASetBlockingHook()).
  5906.  
  5907.           In each case, the original blocking call will terminate as
  5908.           soon as possible with the error WSAEINTR.  (In (1), the
  5909.           termination will not take place until Windows message
  5910.           scheduling has caused control to revert to the blocking
  5911.           routine in Windows Sockets.  In (2), the blocking call will
  5912.           be terminated as soon as the blocking hook function
  5913.           completes.)
  5914.  
  5915.           In the case of a blocking connect() operation, the Windows
  5916.           Sockets implementation will terminate the blocking call as
  5917.           soon as possible, but it may not be possible for the socket
  5918.           resources to be released until the connection has completed
  5919.           (and then been reset) or timed out.  This is likely to be
  5920.           noticeable only if the application immediately tries to open
  5921.           a new socket (if no sockets are available), or to connect()
  5922.           to the same peer.
  5923.  
  5924.           Cancelling an accept() or a select() call does not adversely
  5925.           impact the sockets passed to these calls.  Only the
  5926.           particular call fails; any operation that was legal before
  5927.           the cancel is legal after the cancel, and the state of the
  5928.           socket is not affected in any way.
  5929.  
  5930.           Cancelling any operation other than accept() and select()
  5931.           can leave the socket in an indeterminate state.  If an
  5932.           application cancels a blocking operation on a socket, the
  5933.           only operation that the application can depend on being able
  5934.           to perform on the socket is a call to closesocket(),
  5935.           although other operations may work on some Windows Sockets
  5936.           implementations.  If an application desires maximum
  5937.           portability, it must be careful not to depend on performing
  5938.           operations after a cancel.  An application may reset the
  5939.           connection by setting the timeout on SO_LINGER to 0.
  5940.  
  5941.           If a cancel operation compromised the integrity of a
  5942.           SOCK_STREAM's data stream in any way, the Windows Sockets
  5943.           implementation must reset the connection and fail all future
  5944.           operations other than closesocket() with WSAECONNABORTED.
  5945.  
  5946.  
  5947.  
  5948.                                              WSACancelBlockingCall 113
  5949.  
  5950. Return Value   The value returned by WSACancelBlockingCall() is 0 if
  5951.           the operation was successfully canceled.  Otherwise the
  5952.           value SOCKET_ERROR is returned, and a specific error number
  5953.           may be retrieved by calling WSAGetLastError().
  5954.  
  5955. Comments  Note that it is possible that the network operation
  5956.           completes before the WSACancelBlockingCall()  is processed,
  5957.           for example if data is received into the user buffer at
  5958.           interrupt time while the application is in a blocking hook.
  5959.           In this case, the blocking operation will return
  5960.           successfully as if WSACancelBlockingCall() had never been
  5961.           called.  Note that the WSACancelBlockingCall() still
  5962.           succeeds in this case; the only way to know with certainty
  5963.           that an operation was actually canceled is to check for a
  5964.           return code of WSAEINTR from the blocking call.
  5965.  
  5966. Error Codes                   WSANOTINITIALISED   A successful
  5967.                               WSAStartup() must occur before using
  5968.                               this API.
  5969.  
  5970.           WSAENETDOWN         The Windows Sockets implementation has
  5971.                               detected that the network subsystem has
  5972.                               failed.
  5973.  
  5974.           WSAEINVAL           Indicates that there is no outstanding
  5975.                               blocking call.
  5976.  
  5977.  
  5978.  
  5979. 114 WSACleanup
  5980.  
  5981. 4.3.10 WSACleanup()
  5982. Description    Terminate use of the Windows Sockets DLL.
  5983.  
  5984.           #include <winsock.h>
  5985.  
  5986.           int PASCAL FAR WSACleanup ( void );
  5987.  
  5988. Remarks   An application or DLL is required to perform a (successful)
  5989.           WSAStartup() call before it can use Windows Sockets
  5990.           services.  When it has completed the use of Windows Sockets,
  5991.           the application or DLL must call WSACleanup() to deregister
  5992.           itself from a Windows Sockets implementation and allow the
  5993.           implementation to free any resources allocated on behalf of
  5994.           the application or DLL.  Any open SOCK_STREAM sockets that
  5995.           are connected when WSACleanup() is called are reset; sockets
  5996.           which have been closed with closesocket() but which still
  5997.           have pending data to be sent are not affected--the pending
  5998.           data is still sent.
  5999.  
  6000.           There must be a call to WSACleanup() for every call to
  6001.           WSAStartup() made by a task.  Only the final WSACleanup()
  6002.           for that task does the actual cleanup; the preceding calls
  6003.           simply decrement an internal reference count in the Windows
  6004.           Sockets DLL.  A naive application may ensure that
  6005.           WSACleanup() was called enough times by calling WSACleanup()
  6006.           in a loop until it returns WSANOTINITIALISED.
  6007.  
  6008. Return Value   The return value is 0 if the operation was successful.
  6009.           Otherwise the value SOCKET_ERROR is returned, and a specific
  6010.           error number may be retrieved by calling WSAGetLastError().
  6011.  
  6012. Comments  Attempting to call WSACleanup() from within a blocking hook
  6013.           and then failing to check the return code is a common
  6014.           Windows Sockets programming error.  If an application needs
  6015.           to quit while a blocking call is outstanding, the
  6016.           application must first cancel the blocking call with
  6017.           WSACancelBlockingCall() then issue the WSACleanup() call
  6018.           once control has been returned to the application.
  6019.  
  6020. Notes For
  6021. Windows Sockets
  6022. Suppliers Well-behaved Windows Sockets applications will make a
  6023.           WSACleanup() call to indicate deregistration from a Windows
  6024.           Sockets implementation.  This function can thus, for
  6025.           example, be utilized to free up resources allocated to the
  6026.           specific application.
  6027.  
  6028.           A Windows Sockets implementation must be prepared to deal
  6029.           with an application which terminates without invoking
  6030.           WSACleanup() - for example, as a result of an error.
  6031.  
  6032.           In a multithreaded environment, WSACleanup() terminates
  6033.           Windows Sockets operations for all threads.
  6034.  
  6035.           A Windows Sockets implementation must ensure that
  6036.           WSACleanup() leaves things in a state in which the
  6037.  
  6038.  
  6039.  
  6040.                                                         WSACleanup 115
  6041.  
  6042.           application can invoke WSAStartup() to re-establish Windows
  6043.           Sockets usage.
  6044.  
  6045. Error Codes                   WSANOTINITIALISED   A successful
  6046.                               WSAStartup() must occur before using
  6047.                               this API.
  6048.  
  6049.           WSAENETDOWN         The Windows Sockets implementation has
  6050.                               detected that the network subsystem has
  6051.                               failed.
  6052.  
  6053.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  6054.                               in progress.
  6055.  
  6056. See Also  WSAStartup()
  6057.  
  6058.  
  6059.  
  6060. 116 WSAGetLastError
  6061.  
  6062. 4.3.11 WSAGetLastError()
  6063. Description    Get the error status for the last operation which
  6064.           failed.
  6065.  
  6066.           #include <winsock.h>
  6067.  
  6068.           int PASCAL FAR WSAGetLastError ( void );
  6069.  
  6070. Remarks   This function returns the last network error that occurred.
  6071.           When a particular Windows Sockets API function indicates
  6072.           that an error has occurred, this function should be called
  6073.           to retrieve the appropriate error code.
  6074.  
  6075. Return Value   The return value indicates the error code for the last
  6076.           Windows Sockets API routine performed by this thread.
  6077.  
  6078. Notes For
  6079. Windows Sockets
  6080. Suppliers The use of the WSAGetLastError() function to retrieve the
  6081.           last error code, rather than relying on a global error
  6082.           variable (cf. errno), is required in order to provide
  6083.           compatibility with future multi-threaded environments.
  6084.  
  6085.           Note that in a nonpreemptive Windows environment
  6086.           WSAGetLastError() is used to retrieve only Windows Sockets
  6087.           API errors.  In a preemptive environment, WSAGetLastError()
  6088.           will invoke GetLastError(), which is used to retrieve the
  6089.           error status for all Win32 API functions on a per-thread
  6090.           basis.  For portability, an application should use
  6091.           WSAGetLastError() immediately after the Windows Sockets API
  6092.           function which failed.
  6093.  
  6094. See Also  WSASetLastError()
  6095.  
  6096.  
  6097.  
  6098.                                                      WSAIsBlocking 117
  6099.  
  6100. 4.3.12 WSAIsBlocking()
  6101. Description    Determine if a blocking call is in progress.
  6102.  
  6103.           #include <winsock.h>
  6104.  
  6105.           BOOL PASCAL FAR WSAIsBlocking ( void );
  6106.  
  6107. Remarks   This function allows a task to determine if it is executing
  6108.           while waiting for a previous blocking call to complete.
  6109.  
  6110. Return Value   The return value is TRUE if there is an outstanding
  6111.           blocking function awaiting completion.  Otherwise, it is
  6112.           FALSE.
  6113.  
  6114. Comments  Although a call issued on a blocking socket appears to an
  6115.           application program as though it "blocks", the Windows
  6116.           Sockets DLL has to relinquish the processor to allow other
  6117.           applications to run.  This means that it is possible for the
  6118.           application which issued the blocking call to be re-entered,
  6119.           depending on the message(s) it receives.  In this instance,
  6120.           the WSAIsBlocking() function can be used to ascertain
  6121.           whether the task has been re-entered while waiting for an
  6122.           outstanding blocking call to complete.  Note that Windows
  6123.           Sockets prohibits more than one outstanding call per thread.
  6124.  
  6125. Notes For
  6126. Windows Sockets
  6127. Suppliers A Windows Sockets implementation must prohibit more than one
  6128.           outstanding blocking call per thread.
  6129.  
  6130.  
  6131.  
  6132. 118 WSASetBlockingHook
  6133.  
  6134. 4.3.13 WSASetBlockingHook()
  6135. Description    Establish an application-specific blocking hook
  6136.           function.
  6137.  
  6138.           #include <winsock.h>
  6139.  
  6140.           FARPROC PASCAL FAR WSASetBlockingHook ( FARPROC lpBlockFunc
  6141.           );
  6142.  
  6143.  
  6144.           lpBlockFunc    A pointer to the procedure instance address
  6145.                     of the blocking function to be installed.
  6146.  
  6147. Remarks   This function installs a new function which a Windows
  6148.           Sockets implementation should use to implement blocking
  6149.           socket function calls.
  6150.  
  6151.           A Windows Sockets implementation includes a default
  6152.           mechanism by which blocking socket functions are
  6153.           implemented.  The function WSASetBlockingHook() gives the
  6154.           application the ability to execute its own function at
  6155.           "blocking" time in place of the default function.
  6156.  
  6157.           When an application invokes a blocking Windows Sockets API
  6158.           operation, the Windows Sockets implementation initiates the
  6159.           operation and then enters a loop which is similar to the
  6160.           following pseudocode:
  6161.  
  6162.           for(;;) {
  6163.                /* flush messages for good user response */
  6164.                while(BlockingHook())
  6165.                     ;
  6166.                /* check for WSACancelBlockingCall() */
  6167.                if(operation_cancelled())
  6168.                     break;
  6169.                /* check to see if operation completed */
  6170.                if(operation_complete())
  6171.                     break;     /* normal completion */
  6172.           }
  6173.  
  6174.           Note that Windows Sockets implementations may perform the
  6175.           above steps in a different order; for example, the check for
  6176.           operation complete may occur before calling the blocking
  6177.           hook.  The default BlockingHook() function is equivalent to:
  6178.  
  6179.           BOOL DefaultBlockingHook(void) {
  6180.                MSG msg;
  6181.                BOOL ret;
  6182.                /* get the next message if any */
  6183.                ret = (BOOL)PeekMessage(&msg,NULL,0,0,PM_REMOVE);
  6184.                /* if we got one, process it */
  6185.                if (ret) {
  6186.                     TranslateMessage(&msg);
  6187.                     DispatchMessage(&msg);
  6188.                }
  6189.                /* TRUE if we got a message */
  6190.                return ret;
  6191.  
  6192.  
  6193.  
  6194.                                                 WSASetBlockingHook 119
  6195.  
  6196.           }
  6197.  
  6198.           The WSASetBlockingHook() function is provided to support
  6199.           those applications which require more complex message
  6200.           processing - for example, those employing the MDI (multiple
  6201.           document interface) model.  It is not intended as a
  6202.           mechanism for performing general applications functions.  In
  6203.           particular, the only Windows Sockets API function which may
  6204.           be issued from a custom blocking hook function is
  6205.           WSACancelBlockingCall(), which will cause the blocking loop
  6206.           to terminate.
  6207.  
  6208.           This function must be implemented on a per-task basis for
  6209.           non-multithreaded versions of Windows and on a per-thread
  6210.           basis for multithreaded versions of Windows such as Windows
  6211.           NT.  It thus provides for a particular task or thread to
  6212.           replace the blocking mechanism without affecting other tasks
  6213.           or threads.
  6214.  
  6215.           In multithreaded versions of Windows, there is no default
  6216.           blocking hook--blocking calls block the thread that makes
  6217.           the call.  However, an application may install a specific
  6218.           blocking hook by calling WSASetBlockingHook().
  6219.           This allows easy portability of applications that depend on
  6220.           the blocking hook behavior.
  6221.  
  6222. Return Value   The return value is a pointer to the procedure-instance
  6223.           of the previously installed blocking function.  The
  6224.           application or library that calls the WSASetBlockingHook ()
  6225.           function should save this return value so that it can be
  6226.           restored if necessary.  (If "nesting" is not important, the
  6227.           application may simply discard the value returned by
  6228.           WSASetBlockingHook() and eventually use
  6229.           WSAUnhookBlockingHook() to restore the default mechanism.)
  6230.           If the operation fails, a NULL pointer is returned, and a
  6231.           specific error number may be retrieved by calling
  6232.           WSAGetLastError().
  6233.  
  6234. Error Codes                   WSANOTINITIALISED   A successful
  6235.                               WSAStartup() must occur before using
  6236.                               this API.
  6237.  
  6238.           WSAENETDOWN         The Windows Sockets implementation has
  6239.                               detected that the network subsystem has
  6240.                               failed.
  6241.  
  6242.           WSAEINPROGRESS      A blocking Windows Sockets operation is
  6243.                               in progress.
  6244.  
  6245. See Also  WSAUnhookBlockingHook()
  6246.  
  6247.  
  6248.  
  6249. 120 WSASetLastError
  6250.  
  6251. 4.3.14 WSASetLastError()
  6252. Description    Set the error code which can be retrieved by
  6253.           WSAGetLastError().
  6254.  
  6255.           #include <winsock.h>
  6256.  
  6257.           void PASCAL FAR WSASetLastError ( int iError );
  6258.  
  6259. Remarks   This function allows an application to set the error code to
  6260.           be returned by a subsequent WSAGetLastError() call for the
  6261.           current thread.  Note that any subsequent Windows Sockets
  6262.           routine called by the application will override the error
  6263.           code as set by this routine.
  6264.  
  6265.  
  6266.           iError    Specifies the error code to be returned by a
  6267.                     subsequent WSAGetLastError() call.
  6268.  
  6269. Notes For
  6270. Windows Sockets
  6271. Suppliers In a Win32 environment, this function will invoke
  6272. SetLastError().
  6273.  
  6274. Return Value   None.
  6275.  
  6276. Error Codes                   WSANOTINITIALISED   A successful
  6277.                               WSAStartup() must occur before using
  6278.                               this API.
  6279.  
  6280. See Also  WSAGetLastError()
  6281.  
  6282.  
  6283.  
  6284.                                                         WSAStartup 121
  6285.  
  6286. 4.3.15 WSAStartup()
  6287. Description
  6288.  
  6289.           #include <winsock.h>
  6290.  
  6291.           int PASCAL FAR WSAStartup ( WORD wVersionRequested,
  6292.           LPWSADATA lpWSAData );
  6293.  
  6294.  
  6295.           wVersionRequested   The highest version of Windows Sockets
  6296.                          API support that the caller can use.  The
  6297.                          high order byte specifies the minor version
  6298.                          (revision) number; the low-order byte
  6299.                          specifies the major version number.
  6300.  
  6301.           lpWSAData      A pointer to the WSADATA data structure that
  6302.                          is to receive details of the Windows Sockets
  6303.                          implementation.
  6304.  
  6305. Remarks   This function MUST be the first Windows Sockets function
  6306.           called by an application or DLL.  It allows an application
  6307.           or DLL  to specify the version of Windows Sockets API
  6308.           required and to retrieve details of the specific Windows
  6309.           Sockets implementation.  The application or DLL may only
  6310.           issue further Windows Sockets API functions after a
  6311.           successful WSAStartup() invocation.
  6312.  
  6313.           In order to support future Windows Sockets implementations
  6314.           and applications which may have functionality differences
  6315.           from Windows Sockets 1.1, a negotiation takes place in
  6316.           WSAStartup().  The caller of WSAStartup() and the Windows
  6317.           Sockets DLL indicate to each other the highest version that
  6318.           they can support, and each confirms that the other's highest
  6319.           version is acceptable.  Upon entry to WSAStartup(), the
  6320.           Windows Sockets DLL examines the version requested by the
  6321.           application.  If this version is higher than the lowest
  6322.           version supported by the DLL, the call succeeds and the DLL
  6323.           returns in wHighVersion the highest version it supports and
  6324.           in wVersion the minimum of its high version and
  6325.           wVersionRequested.  The Windows Sockets DLL then assumes
  6326.           that the application will use wVersion.  If the wVersion
  6327.           field of the WSADATA structure is unacceptable to the
  6328.           caller, it should call WSACleanup() and either search for
  6329.           another Windows Sockets DLL or fail to initialize.
  6330.  
  6331.           This negotiation allows both a Windows Sockets DLL and a
  6332.           Windows Sockets application to support a range of Windows
  6333.           Sockets versions.  An application can successfully utilize a
  6334.           Windows Sockets DLL if there is any overlap in the version
  6335.           ranges.  The following chart gives examples of how
  6336.           WSAStartup() works in conjunction with different application
  6337.           and Windows Sockets DLL versions:
  6338.  
  6339.  
  6340.  
  6341. 122 WSAStartup
  6342.  
  6343.  
  6344.  
  6345. App versions DLL Versions wVersionRequested wVersion wHighVersion End Result 
  6346.  
  6347. 1.1          1.1          1.1               1.1      1.1          use 1.1
  6348.  
  6349. 1.0 1.1      1.0          1.1               1.0      1.0          use 1.0 
  6350.  
  6351. 1.0          1.0 1.1      1.0               1.0      1.1          use 1.0
  6352.  
  6353. 1.1          1.0 1.1      1.1               1.1      1.1          use 1.1
  6354.  
  6355. 1.1          1.0          1.1               1.0      1.0          Application fails
  6356.  
  6357. 1.0          1.1          1.0               ---      ---          WSAVERNOTSUPPORTED
  6358.  
  6359. 1.0 1.1      1.0 1.1      1.1               1.1      1.1          use 1.1
  6360.  
  6361. 1.1 2.0      1.1          2.0               1.1      1.1          use 1.1
  6362.  
  6363. 2.0          1.1          2.0               1.1      1.1          Application fails
  6364.  
  6365.  
  6366.           The following code fragment demonstrates how an application
  6367.           which supports only version 1.1 of Windows Sockets makes a
  6368.           WSAStartup() call:
  6369.  
  6370.           WORD wVersionRequested;
  6371.           WSADATA wsaData;
  6372.           int err;
  6373.  
  6374.           wVersionRequested = MAKEWORD( 1, 1 );
  6375.  
  6376.           err = WSAStartup( wVersionRequested, &wsaData );
  6377.           if ( err != 0 ) {
  6378.               /* Tell the user that we couldn't find a useable */
  6379.               /* winsock.dll.                                  */
  6380.               return;
  6381.           }
  6382.  
  6383.           /* Confirm that the Windows Sockets DLL supports 1.1.*/
  6384.           /* Note that if the DLL supports versions greater    */
  6385.  
  6386.  
  6387.  
  6388.                                                         WSAStartup 123
  6389.  
  6390.           /* than 1.1 in addition to 1.1, it will still return */
  6391.           /* 1.1 in wVersion since that is the version we      */
  6392.           /* requested.                                        */
  6393.  
  6394.           if ( LOBYTE( wsaData.wVersion ) != 1 ||
  6395.                    HIBYTE( wsaData.wVersion ) != 1 ) {
  6396.               /* Tell the user that we couldn't find a useable */
  6397.               /* winsock.dll.                                  */
  6398.               WSACleanup( );
  6399.               return;
  6400.           }
  6401.  
  6402.           /* The Windows Sockets DLL is acceptable.  Proceed.  */
  6403.  
  6404.           And this code fragment demonstrates how a Windows Sockets
  6405.           DLL which supports only version 1.1 performs the
  6406.           WSAStartup() negotiation:
  6407.  
  6408.           /* Make sure that the version requested is >= 1.1.   */
  6409.           /* The low byte is the major version and the high    */
  6410.           /* byte is the minor version.                        */
  6411.  
  6412.           if ( LOBYTE( wVersionRequested ) < 1 ||
  6413.                ( LOBYTE( wVersionRequested ) == 1 &&
  6414.                  HIBYTE( wVersionRequested ) < 1 ) {
  6415.               return WSAVERNOTSUPPORTED;
  6416.           }
  6417.  
  6418.           /* Since we only support 1.1, set both wVersion and  */
  6419.           /* wHighVersion to 1.1.                              */
  6420.  
  6421.           lpWsaData->wVersion = MAKEWORD( 1, 1 );
  6422.           lpWsaData->wHighVersion = MAKEWORD( 1, 1 );
  6423.  
  6424.           Once an application or DLL has made a successful
  6425.           WSAStartup() call, it may proceed to make other Windows
  6426.           Sockets API calls as needed.  When it has finished using the
  6427.           services of the Windows Sockets DLL, the application or DLL
  6428.           must call WSACleanup() in order to allow the Windows Sockets
  6429.           DLL to free any resources for the application.
  6430.  
  6431.           Details of the actual Windows Sockets implementation are
  6432.           described in the WSAData structure defined as follows:
  6433.  
  6434.           struct WSAData {
  6435.                WORD           wVersion;
  6436.                WORD           wHighVersion;
  6437.                char 
  6438.                szDescription[WSADESCRIPTION_LEN+1];
  6439.                char           szSystemStatus[WSASYSSTATUS_LEN+1];
  6440.                unsigned short iMaxSockets;
  6441.                unsigned short iMaxUdpDg;
  6442.                char FAR *          lpVendorInfo;
  6443.           };
  6444.  
  6445.           The members of this structure are:
  6446.           Element   Usage
  6447.  
  6448.  
  6449.  
  6450. 124 WSAStartup
  6451.  
  6452.           wVersion  The version of the Windows Sockets specification
  6453.                     that the Windows Sockets DLL expects the caller to
  6454.                     use.
  6455.           wHighVersion   The highest version of the Windows Sockets
  6456.                     specification that this DLL can support (also
  6457.                     encoded as above).  Normally this will be the same
  6458.                     as wVersion.
  6459.           szDescription  A null-terminated ASCII string into which the
  6460.                     Windows Sockets DLL copies a description of the
  6461.                     Windows Sockets implementation, including vendor
  6462.                     identification.  The text (up to 256 characters in
  6463.                     length) may contain any characters, but vendors
  6464.                     are cautioned against including control and
  6465.                     formatting characters: the most likely use that an
  6466.                     application will put this to is to display it
  6467.                     (possibly truncated) in a status message.
  6468.           szSystemStatus A null-terminated ASCII string into which the
  6469.                     Windows Sockets DLL copies relevant status or
  6470.                     configuration information.  The Windows Sockets
  6471.                     DLL should use this field only if the information
  6472.                     might be useful to the user or  support staff: it
  6473.                     should not be considered as an extension of the
  6474.                     szDescription field.
  6475.           iMaxSockets    The maximum number of sockets which a single
  6476.                     process can potentially open.  A Windows Sockets
  6477.                     implementation may provide a global pool of
  6478.                     sockets for allocation to any process;
  6479.                     alternatively it may allocate per-process
  6480.                     resources for sockets.  The number may well
  6481.                     reflect the way in which the Windows Sockets DLL
  6482.                     or the networking software was configured.
  6483.                     Application writers may use this number as a crude
  6484.                     indication of whether the Windows Sockets
  6485.                     implementation is usable by the application.  For
  6486.                     example, an X Windows server might check
  6487.                     iMaxSockets when first started: if it is less than
  6488.                     8, the application would display an error message
  6489.                     instructing the user to reconfigure the networking
  6490.                     software.  (This is a situation in which the
  6491.                     szSystemStatus text might be used.)  Obviously
  6492.                     there is no guarantee that a particular
  6493.                     application can actually allocate iMaxSockets
  6494.                     sockets, since there may be other Windows Sockets
  6495.                     applications in use.
  6496.           iMaxUdpDg The size in bytes of the largest UDP datagram that
  6497.                     can be sent or received by a Windows Sockets
  6498.                     application.  If the implementation imposes no
  6499.                     limit, iMaxUdpDg is zero.  In many implementations
  6500.                     of Berkeley sockets, there is an implicit limit of
  6501.                     8192 bytes on UDP datagrams (which are fragmented
  6502.                     if necessary).  A Windows Sockets implementation
  6503.                     may impose a limit based, for instance, on the
  6504.                     allocation of fragment reassembly buffers.  The
  6505.                     minimum value of iMaxUdpDg for a compliant Windows
  6506.                     Sockets implementation is 512.  Note that
  6507.                     regardless of the value of iMaxUdpDg, it is
  6508.                     inadvisable to attempt to send a broadcast
  6509.  
  6510.  
  6511.  
  6512.                                                         WSAStartup 125
  6513.  
  6514.                     datagram which is larger than the Maximum
  6515.                     Transmission Unit (MTU) for the network.  (The
  6516.                     Windows Sockets API does not provide a mechanism
  6517.                     to discover the MTU, but it must be no less than
  6518.                     512 bytes.)
  6519.           lpVendorInfo   A far pointer to a vendor-specific data
  6520.                     structure.  The definition of this structure (if
  6521.                     supplied) is beyond the scope of this
  6522.                     specification.
  6523.  
  6524.           An application or DLL may call WSAStartup() more than once
  6525.           if it needs to obtain the WSAData structure information more
  6526.           than once.  However, the wVersionRequired parameter is
  6527.           assumed to be the same on all calls to WSAStartup(); that
  6528.           is, an application or DLL cannot change the version of
  6529.           Windows Sockets it expects after the initial call to
  6530.           WSAStartup().
  6531.  
  6532.           There must be one WSACleanup() call corresponding to every
  6533.           WSAStartup() call to allow third-party DLLs to make use of a
  6534.           Windows Sockets DLL on behalf of an application.  This
  6535.           means, for example, that if an application calls
  6536.           WSAStartup() three times, it must call WSACleanup() three
  6537.           times.  The first two calls to WSACleanup() do nothing
  6538.           except decrement an internal counter; the final WSACleanup()
  6539.           call for the task does all necessary resource deallocation
  6540.           for the task.
  6541.  
  6542.  
  6543. Return Value   WSAStartup() returns zero if successful.  Otherwise it
  6544.           returns one of the error codes listed below.  Note that the
  6545.           normal mechanism whereby the application calls
  6546.           WSAGetLastError() to determine the error code cannot be
  6547.           used, since the Windows Sockets DLL may not have established
  6548.           the client data area where the "last error" information is
  6549.           stored.
  6550.  
  6551. Notes For
  6552. Windows Sockets
  6553. Suppliers Each Windows Sockets application MUST make a WSAStartup()
  6554.           call before issuing any other Windows Sockets API calls.
  6555.           This function can thus be utilized for initialization
  6556.           purposes.
  6557.  
  6558.           Further issues are discussed in the notes for WSACleanup().
  6559.  
  6560. Error Codes                   WSASYSNOTREADY Indicates that the
  6561.                               underlying network subsystem is not
  6562.                               ready for network communication.
  6563.  
  6564.           WSAVERNOTSUPPORTED
  6565.                               The version of Windows Sockets API
  6566.                               support requested is not provided by
  6567.                               this particular Windows Sockets
  6568.                               implementation.
  6569.  
  6570.  
  6571.  
  6572. 126 WSAStartup
  6573.  
  6574.           WSAEINVAL           The Windows Sockets version specified by
  6575.                               the application is not supported by this
  6576.                               DLL.
  6577.  
  6578. See Also  send(), sendto(), WSACleanup()
  6579.  
  6580.  
  6581.  
  6582.                                              WSAUnhookBlockingHook 127
  6583.  
  6584. 4.3.16 WSAUnhookBlockingHook()
  6585. Description    Restore the default blocking hook function.
  6586.  
  6587.           #include <winsock.h>
  6588.  
  6589.           int PASCAL FAR WSAUnhookBlockingHook ( void );
  6590.  
  6591. Remarks   This function removes any previous blocking hook that has
  6592.           been installed and reinstalls the default blocking
  6593.           mechanism.
  6594.  
  6595.           WSAUnhookBlockingHook() will always install the default
  6596.           mechanism, not the previous mechanism.  If an application
  6597.           wish to nest blocking hooks - i.e. to establish a temporary
  6598.           blocking hook function and then revert to the previous
  6599.           mechanism (whether the default or one established by an
  6600.           earlier WSASetBlockingHook()) - it must save and restore the
  6601.           value returned by WSASetBlockingHook(); it cannot use
  6602.           WSAUnhookBlockingHook().
  6603.  
  6604.           In multithreaded versions of Windows such as Windows NT,
  6605.           there is no default blocking hook.  Calling
  6606.           WSAUnhookBlockingHook() disables any blocking hook installed
  6607.           by the application and any blocking calls made block the
  6608.           thread which made the call.
  6609.  
  6610. Return Value   The return value is 0 if the operation was successful.
  6611.           Otherwise the value SOCKET_ERROR is returned, and a specific
  6612.           error number may be retrieved by calling WSAGetLastError().
  6613.  
  6614. Error Codes                   WSANOTINITIALISED   A successful
  6615.                               WSAStartup() must occur before using
  6616.                               this API.
  6617.  
  6618. See Also  WSASetBlockingHook()
  6619.  
  6620.  
  6621.  
  6622. 128 Appendix A1: Error Codes
  6623.  
  6624.  
  6625. Appendix A.  Error Codes and Header Files
  6626.  
  6627. A.1 Error Codes
  6628. The following is a list of possible error codes returned by the
  6629. WSAGetLastError() call, along with their explanations.  The error
  6630. numbers are consistently set across all Windows Sockets-compliant
  6631. implementations.
  6632.  
  6633.  
  6634.  
  6635.                                           Appendix A1: Error Codes 129
  6636.  
  6637.  
  6638. Windows        Berkeley       Err  Interpretation
  6639. Sockets code   equivalent     or
  6640.  
  6641.  
  6642.  
  6643. WSAEINTR       EINTR               As in standard C
  6644.                               100
  6645.                               04
  6646. WSAEBADF       EBADF               As in standard C
  6647.                               100
  6648.                               09
  6649. WSAEACCES      EACCES              As in standard C
  6650.                               100
  6651.                               13
  6652. WSAEFAULT      EFAULT              As in standard C
  6653.                               100
  6654.                               14
  6655. WSAEINVAL      EINVAL              As in standard C
  6656.                               100
  6657.                               22
  6658. WSAEMFILE      EMFILE              As in standard C
  6659.                               100
  6660.                               24
  6661.  
  6662. WSAEWOULDBLOC  EWOULDBLOCK         As in BSD
  6663.                               100
  6664. K                             35
  6665. WSAEINPROGRES  EINPROGRESS         This error is returned
  6666.                               100
  6667. S                                  if any
  6668.                               36
  6669.                                    Windows Sockets API
  6670.                                    function is
  6671.                                    called while a blocking
  6672.                                    function is
  6673.                                    in progress.
  6674. WSAEALREADY    EALREADY            As in BSD
  6675.                               100
  6676.                               37
  6677. WSAENOTSOCK    ENOTSOCK            As in BSD
  6678.                               100
  6679.                               38
  6680. WSAEDESTADDRR  EDESTADDRREQ   100  As in BSD
  6681. EQ                            39
  6682. WSAEMSGSIZE    EMSGSIZE            As in BSD
  6683.                               100
  6684.                               40
  6685. WSAEPROTOTYPE  EPROTOTYPE          As in BSD
  6686.                               100
  6687.                               41
  6688. WSAENOPROTOOP  ENOPROTOOPT         As in BSD
  6689.                               100
  6690. T                             42
  6691. WSAEPROTONOSU  EPROTONOSUPPO  100  As in BSD
  6692. PPORT          RT             43
  6693. WSAESOCKTNOSU  ESOCKTNOSUPPO       As in BSD
  6694.                               100
  6695. PPORT          RT             44
  6696. WSAEOPNOTSUPP  EOPNOTSUPP          As in BSD
  6697.                               100
  6698.                               45
  6699. WSAEPFNOSUPPO  EPFNOSUPPORT   100  As in BSD
  6700. RT                            46
  6701. WSAEAFNOSUPPO  EAFNOSUPPORT   100  As in BSD
  6702. RT                            47
  6703. WSAEADDRINUSE  EADDRINUSE     100  As in BSD
  6704.                               48
  6705. WSAEADDRNOTAV  EADDRNOTAVAIL       As in BSD
  6706.                               100
  6707. AIL                           49
  6708.  
  6709.  
  6710.  
  6711. 130 Appendix A1: Error Codes
  6712.  
  6713. WSAENETDOWN    ENETDOWN            As in BSD.  This error
  6714.                               100
  6715.                               50   may be reported at any
  6716.                                    time if the Windows
  6717.                                    Sockets implementation
  6718.                                    detects an underlying
  6719.                                    failure.
  6720. WSAENETUNREAC  ENETUNREACH         As in BSD
  6721.                               100
  6722. H                             51
  6723. WSAENETRESET   ENETRESET           As in BSD
  6724.                               100
  6725.                               52
  6726. WSAECONNABORT  ECONNABORTED        As in BSD
  6727.                               100
  6728. ED                            53
  6729. WSAECONNRESET  ECONNRESET          As in BSD
  6730.                               100
  6731.                               54
  6732. WSAENOBUFS     ENOBUFS             As in BSD
  6733.                               100
  6734.                               55
  6735. WSAEISCONN     EISCONN             As in BSD
  6736.                               100
  6737.                               56
  6738. WSAENOTCONN    ENOTCONN            As in BSD
  6739.                               100
  6740.                               57
  6741. WSAESHUTDOWN   ESHUTDOWN           As in BSD
  6742.                               100
  6743.                               58
  6744. WSAETOOMANYRE  ETOOMANYREFS        As in BSD
  6745.                               100
  6746. FS                            59
  6747. WSAETIMEDOUT   ETIMEDOUT      100  As in BSD
  6748.                               60
  6749. WSAECONNREFUS  ECONNREFUSED        As in BSD
  6750.                               100
  6751. ED                            61
  6752. WSAELOOP       ELOOP               As in BSD
  6753.                               100
  6754.                               62
  6755. WSAENAMETOOLO  ENAMETOOLONG        As in BSD
  6756.                               100
  6757. NG                            63
  6758. WSAEHOSTDOWN   EHOSTDOWN           As in BSD
  6759.                               100
  6760.                               64
  6761. WSAEHOSTUNREA  EHOSTUNREACH        As in BSD
  6762.                               100
  6763. CH                            65
  6764.  
  6765. WSASYSNOTREAD                      Returned by
  6766.                               100
  6767. Y                             91   WSAStartup()
  6768.                                    indicating that the
  6769.                                    network subsystem is
  6770.                                    unusable.
  6771. WSAVERNOTSUPP                      Returned by
  6772.                               100
  6773. ORTED                         92   WSAStartup()
  6774.                                    indicating that the
  6775.                                    Windows Sockets
  6776.                                    DLL cannot support this
  6777.                                    app.
  6778. WSANOTINITIAL                      Returned by any
  6779.                               100
  6780. ISED                               function except
  6781.                               93
  6782.                                    WSAStartup() indicating
  6783.                                    that a successful
  6784.                                    WSAStartup() has not
  6785.                                    yet been performed.
  6786.  
  6787. WSAHOST_NOT_F  HOST_NOT_FOUN       As in BSD.
  6788.                               110
  6789. OUND           D              01
  6790.  
  6791.  
  6792.  
  6793.                                           Appendix A1: Error Codes 131
  6794.  
  6795. WSATRY_AGAIN   TRY_AGAIN           As in BSD
  6796.                               110
  6797.                               02
  6798. WSANO_RECOVER  NO_RECOVERY         As in BSD
  6799.                               110
  6800. Y                             03
  6801. WSANO_DATA     NO_DATA             As in BSD
  6802.                               110
  6803.                               04
  6804.  
  6805.  
  6806.  
  6807. The first set of definitions is present to resolve contentions between
  6808. standard C error codes which may be defined inconsistently between
  6809. various C compilers.
  6810.  
  6811. The second set of definitions provides Windows Sockets versions of
  6812. regular Berkeley Sockets error codes.
  6813.  
  6814. The third set of definitions consists of extended Windows Sockets-
  6815. specific error codes.
  6816.  
  6817. The fourth set of errors are returned by Windows Sockets getXbyY() and
  6818. WSAAsyncGetXByY() functions, and correspond to the errors which in
  6819. Berkeley software would be returned in the h_errno variable.  They
  6820. correspond to various failures which may be returned by the Domain
  6821. Name Service.  If the Windows Sockets implementation  does not use the
  6822. DNS, it will use the most appropriate code.  In general, a Windows
  6823. Sockets application should interpret WSAHOST_NOT_FOUND and WSANO_DATA
  6824. as indicating that the key (name, address, etc.) was not found,, while
  6825. WSATRY_AGAIN and WSANO_RECOVERY suggest that the name service itself
  6826. is non-operational.
  6827.  
  6828. The error numbers are derived from the winsock.h header file listed in
  6829. section A.2.2, and are based on the fact that Windows Sockets error
  6830. numbers are computed by adding 10000 to the "normal" Berkeley error
  6831. number.
  6832.  
  6833. Note that this table does not include all of the error codes defined
  6834. in winsock.h.  This is because it includes only errors which might
  6835. reasonably be returned by a Windows Sockets implementation: winsock.h,
  6836. on the other hand, includes a full set of BSD definitions to ensure
  6837. compatibility with ported software.
  6838.  
  6839.  
  6840.  
  6841. 132 Appendix A2: Header Files
  6842.  
  6843.  
  6844. A.2 Header Files
  6845. A.2.1 Berkeley Header Files
  6846. A Windows Sockets supplier who provides a development kit to support
  6847. the development of Windows Sockets applications must supply a set of
  6848. vestigial header files with names that match a number of the header
  6849. files in the Berkeley software distribution.  These files are provided
  6850. for source code compatibility only, and each consists of three lines:
  6851.  
  6852. #ifndef _WINSOCKAPI_
  6853. #include <winsock.h>
  6854. #endif
  6855.  
  6856. The header files provided for compatibility are:
  6857. netdb.h
  6858. arpa/inet.h
  6859. sys/time.h
  6860. sys/socket.h
  6861. netinet/in.h
  6862.  
  6863. The file winsock.h contains all of the type and structure definitions,
  6864. constants, macros, and function prototypes used by the Windows Sockets
  6865. specification.  An application writer may choose to ignore the
  6866. compatibility headers and include winsock.h in each source file.
  6867.  
  6868.  
  6869.  
  6870.                                                          winsock.h 133
  6871.  
  6872.  
  6873. A.2.2 Windows Sockets Header File - winsock.h
  6874.  
  6875. The winsock.h header file includes a number of types and definitions
  6876. from the standard Windows header file windows.h.  The windows.h in the
  6877. Windows 3.0 SDK (Software Developer's Kit) lacks a #include guard, so
  6878. if you need to include windows.h as well as winsock.h, you should
  6879. define the symbol _INC_WINDOWS before #including winsock.h, as
  6880. follows:
  6881.           #include <windows.h>
  6882.           #define _INC_WINDOWS
  6883.           #include <winsock.h>
  6884. Users of the SDK for Windows 3.1 and later need not do this.
  6885.  
  6886. A Windows Sockets DLL vendor MUST NOT make any modifications to this
  6887. header file which could impact binary compatibility of Windows Sockets
  6888. applications.  The constant values, function parameters and return
  6889. codes, and the like must remain consistent across all Windows Sockets
  6890. DLL vendors.
  6891.  
  6892.  
  6893. /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
  6894.  *
  6895.  * This header file corresponds to version 1.1 of the Windows Sockets specification.
  6896.  *
  6897.  * This file includes parts which are Copyright (c) 1982-1986 Regents
  6898.  * of the University of California.  All rights reserved.  The
  6899.  * Berkeley Software License Agreement specifies the terms and
  6900.  * conditions for redistribution.
  6901.  */
  6902.  
  6903. #ifndef _WINSOCKAPI_
  6904. #define _WINSOCKAPI_
  6905.  
  6906. /*
  6907.  * Pull in WINDOWS.H if necessary
  6908.  */
  6909. #ifndef _INC_WINDOWS
  6910. #include <windows.h>
  6911. #endif /* _INC_WINDOWS */
  6912.  
  6913. /*
  6914.  * Basic system type definitions, taken from the BSD file sys/types.h.
  6915.  */
  6916. typedef unsigned char   u_char;
  6917. typedef unsigned short  u_short;
  6918. typedef unsigned int    u_int;
  6919. typedef unsigned long   u_long;
  6920.  
  6921. /*
  6922.  * The new type to be used in all
  6923.  * instances which refer to sockets.
  6924.  */
  6925. typedef u_int           SOCKET;
  6926.  
  6927. /*
  6928.  * Select uses arrays of SOCKETs.  These macros manipulate such
  6929.  * arrays.  FD_SETSIZE may be defined by the user before including
  6930.  * this file, but the default here should be >= 64.
  6931.  *
  6932.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  6933.  * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  6934.  */
  6935. #ifndef FD_SETSIZE
  6936. #define FD_SETSIZE      64
  6937. #endif /* FD_SETSIZE */
  6938.  
  6939. typedef struct fd_set {
  6940.         u_short fd_count;               /* how many are SET? */
  6941.         SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
  6942. } fd_set;
  6943.  
  6944. extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
  6945.  
  6946. #define FD_CLR(fd, set) do { \
  6947.     u_int __i; \
  6948.     for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
  6949.         if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
  6950.             while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
  6951.                 ((fd_set FAR *)(set))->fd_array[__i] = \
  6952.                     ((fd_set FAR *)(set))->fd_array[__i+1]; \
  6953.                 __i++; \
  6954.             } \
  6955.             ((fd_set FAR *)(set))->fd_count--; \
  6956.             break; \
  6957.         } \
  6958.     } \
  6959. } while(0)
  6960.  
  6961. #define FD_SET(fd, set) do { \
  6962.     if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  6963.         ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=fd;\
  6964. } while(0)
  6965.  
  6966. #define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
  6967.  
  6968. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)fd, (fd_set FAR *)set)
  6969.  
  6970. /*
  6971.  * Structure used in select() call, taken from the BSD file sys/time.h.
  6972.  */
  6973. struct timeval {
  6974.         long    tv_sec;         /* seconds */
  6975.         long    tv_usec;        /* and microseconds */
  6976. };
  6977.  
  6978. /*
  6979.  * Operations on timevals.
  6980.  *
  6981.  * NB: timercmp does not work for >= or <=.
  6982.  */
  6983. #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  6984. #define timercmp(tvp, uvp, cmp) \
  6985.         ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  6986.          (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  6987. #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
  6988.  
  6989. /*
  6990.  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
  6991.  *
  6992.  *
  6993.  * Ioctl's have the command encoded in the lower word,
  6994.  * and the size of any in or out parameters in the upper
  6995.  * word.  The high 2 bits of the upper word are used
  6996.  * to encode the in/out status of the parameter; for now
  6997.  * we restrict parameters to at most 128 bytes.
  6998.  */
  6999. #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
  7000. #define IOC_VOID        0x20000000      /* no parameters */
  7001. #define IOC_OUT         0x40000000      /* copy out parameters */
  7002. #define IOC_IN          0x80000000      /* copy in parameters */
  7003. #define IOC_INOUT       (IOC_IN|IOC_OUT)
  7004.                                         /* 0x20000000 distinguishes new &
  7005.                                            old ioctl's */
  7006. #define _IO(x,y)        (IOC_VOID|(x<<8)|y)
  7007.  
  7008. #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  7009.  
  7010. #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  7011.  
  7012. #define FIONREAD    _IOR('f', 127, u_long) /* get # bytes to read */
  7013. #define FIONBIO     _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
  7014. #define FIOASYNC    _IOW('f', 125, u_long) /* set/clear async i/o */
  7015.  
  7016. /* Socket I/O Controls */
  7017. #define SIOCSHIWAT  _IOW('s',  0, u_long)  /* set high watermark */
  7018. #define SIOCGHIWAT  _IOR('s',  1, u_long)  /* get high watermark */
  7019. #define SIOCSLOWAT  _IOW('s',  2, u_long)  /* set low watermark */
  7020. #define SIOCGLOWAT  _IOR('s',  3, u_long)  /* get low watermark */
  7021. #define SIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark? */
  7022.  
  7023. /*
  7024.  * Structures returned by network data base library, taken from the
  7025.  * BSD file netdb.h.  All addresses are supplied in host order, and
  7026.  * returned in network order (suitable for use in system calls).
  7027.  */
  7028.  
  7029. struct  hostent {
  7030.         char    FAR * h_name;           /* official name of host */
  7031.         char    FAR * FAR * h_aliases;  /* alias list */
  7032.         short   h_addrtype;             /* host address type */
  7033.         short   h_length;               /* length of address */
  7034.         char    FAR * FAR * h_addr_list; /* list of addresses */
  7035. #define h_addr  h_addr_list[0]          /* address, for backward compat */
  7036. };
  7037.  
  7038. /*
  7039.  * It is assumed here that a network number
  7040.  * fits in 32 bits.
  7041.  */
  7042. struct  netent {
  7043.         char    FAR * n_name;           /* official name of net */
  7044.         char    FAR * FAR * n_aliases;  /* alias list */
  7045.         short   n_addrtype;             /* net address type */
  7046.         u_long  n_net;                  /* network # */
  7047. };
  7048.  
  7049. struct  servent {
  7050.         char    FAR * s_name;           /* official service name */
  7051.         char    FAR * FAR * s_aliases;  /* alias list */
  7052.         short   s_port;                 /* port # */
  7053.         char    FAR * s_proto;          /* protocol to use */
  7054. };
  7055.  
  7056. struct  protoent {
  7057.         char    FAR * p_name;           /* official protocol name */
  7058.         char    FAR * FAR * p_aliases;  /* alias list */
  7059.         short   p_proto;                /* protocol # */
  7060. };
  7061.  
  7062. /*
  7063.  * Constants and structures defined by the internet system,
  7064.  * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  7065.  */
  7066.  
  7067. /*
  7068.  * Protocols
  7069.  */
  7070. #define IPPROTO_IP              0               /* dummy for IP */
  7071. #define IPPROTO_ICMP            1               /* control message protocol */
  7072. #define IPPROTO_GGP             2               /* gateway^2 (deprecated) */
  7073. #define IPPROTO_TCP             6               /* tcp */
  7074. #define IPPROTO_PUP             12              /* pup */
  7075. #define IPPROTO_UDP             17              /* user datagram protocol */
  7076. #define IPPROTO_IDP             22              /* xns idp */
  7077. #define IPPROTO_ND              77              /* UNOFFICIAL net disk proto */
  7078.  
  7079. #define IPPROTO_RAW             255             /* raw IP packet */
  7080. #define IPPROTO_MAX             256
  7081.  
  7082. /*
  7083.  * Port/socket numbers: network standard functions
  7084.  */
  7085. #define IPPORT_ECHO             7
  7086. #define IPPORT_DISCARD          9
  7087. #define IPPORT_SYSTAT           11
  7088. #define IPPORT_DAYTIME          13
  7089. #define IPPORT_NETSTAT          15
  7090. #define IPPORT_FTP              21
  7091. #define IPPORT_TELNET           23
  7092. #define IPPORT_SMTP             25
  7093. #define IPPORT_TIMESERVER       37
  7094. #define IPPORT_NAMESERVER       42
  7095. #define IPPORT_WHOIS            43
  7096. #define IPPORT_MTP              57
  7097.  
  7098. /*
  7099.  * Port/socket numbers: host specific functions
  7100.  */
  7101. #define IPPORT_TFTP             69
  7102. #define IPPORT_RJE              77
  7103. #define IPPORT_FINGER           79
  7104. #define IPPORT_TTYLINK          87
  7105. #define IPPORT_SUPDUP           95
  7106.  
  7107. /*
  7108.  * UNIX TCP sockets
  7109.  */
  7110. #define IPPORT_EXECSERVER       512
  7111. #define IPPORT_LOGINSERVER      513
  7112. #define IPPORT_CMDSERVER        514
  7113. #define IPPORT_EFSSERVER        520
  7114.  
  7115. /*
  7116.  * UNIX UDP sockets
  7117.  */
  7118. #define IPPORT_BIFFUDP          512
  7119. #define IPPORT_WHOSERVER        513
  7120. #define IPPORT_ROUTESERVER      520
  7121.                                         /* 520+1 also used */
  7122.  
  7123. /*
  7124.  * Ports < IPPORT_RESERVED are reserved for
  7125.  * privileged processes (e.g. root).
  7126.  */
  7127. #define IPPORT_RESERVED         1024
  7128.  
  7129. /*
  7130.  * Link numbers
  7131.  */
  7132. #define IMPLINK_IP              155
  7133. #define IMPLINK_LOWEXPER        156
  7134. #define IMPLINK_HIGHEXPER       158
  7135.  
  7136. /*
  7137.  * Internet address (old style... should be updated)
  7138.  */
  7139. struct in_addr {
  7140.         union {
  7141.                 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  7142.                 struct { u_short s_w1,s_w2; } S_un_w;
  7143.                 u_long S_addr;
  7144.         } S_un;
  7145. #define s_addr  S_un.S_addr
  7146.                                 /* can be used for most tcp & ip code */
  7147. #define s_host  S_un.S_un_b.s_b2
  7148.                                 /* host on imp */
  7149. #define s_net   S_un.S_un_b.s_b1
  7150.                                 /* network */
  7151. #define s_imp   S_un.S_un_w.s_w2
  7152.                                 /* imp */
  7153. #define s_impno S_un.S_un_b.s_b4
  7154.                                 /* imp # */
  7155. #define s_lh    S_un.S_un_b.s_b3
  7156.                                 /* logical host */
  7157. };
  7158.  
  7159. /*
  7160.  * Definitions of bits in internet address integers.
  7161.  * On subnets, the decomposition of addresses to host and net parts
  7162.  * is done according to subnet mask, not the masks here.
  7163.  */
  7164. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
  7165. #define IN_CLASSA_NET           0xff000000
  7166. #define IN_CLASSA_NSHIFT        24
  7167. #define IN_CLASSA_HOST          0x00ffffff
  7168. #define IN_CLASSA_MAX           128
  7169.  
  7170. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
  7171. #define IN_CLASSB_NET           0xffff0000
  7172. #define IN_CLASSB_NSHIFT        16
  7173. #define IN_CLASSB_HOST          0x0000ffff
  7174. #define IN_CLASSB_MAX           65536
  7175.  
  7176. #define IN_CLASSC(i)            (((long)(i) & 0xc0000000) == 0xc0000000)
  7177. #define IN_CLASSC_NET           0xffffff00
  7178. #define IN_CLASSC_NSHIFT        8
  7179. #define IN_CLASSC_HOST          0x000000ff
  7180.  
  7181. #define INADDR_ANY              (u_long)0x00000000
  7182. #define INADDR_LOOPBACK         0x7f000001
  7183. #define INADDR_BROADCAST        (u_long)0xffffffff    
  7184. #define INADDR_NONE             0xffffffff
  7185.  
  7186. /*
  7187.  * Socket address, internet style.
  7188.  */
  7189. struct sockaddr_in {
  7190.         short   sin_family;
  7191.         u_short sin_port;
  7192.         struct  in_addr sin_addr;
  7193.         char    sin_zero[8];
  7194. };
  7195.  
  7196. #define WSADESCRIPTION_LEN      256
  7197. #define WSASYS_STATUS_LEN       128
  7198.  
  7199. typedef struct WSAData {
  7200.         WORD                    wVersion;
  7201.         WORD                    wHighVersion;
  7202.         char                    szDescription[WSADESCRIPTION_LEN+1];
  7203.         char                    szSystemStatus[WSASYS_STATUS_LEN+1];
  7204.         unsigned short          iMaxSockets;
  7205.         unsigned short          iMaxUdpDg;
  7206.         char FAR *              lpVendorInfo;
  7207. } WSADATA;
  7208.  
  7209. typedef WSADATA FAR *LPWSADATA;
  7210.  
  7211. /*
  7212.  * Options for use with [gs]etsockopt at the IP level.
  7213.  */
  7214. #define IP_OPTIONS      1               /* set/get IP per-packet options */
  7215.  
  7216. /*
  7217.  * Definitions related to sockets: types, address families, options,
  7218.  * taken from the BSD file sys/socket.h.
  7219.  */
  7220.  
  7221. /*
  7222.  * This is used instead of -1, since the
  7223.  * SOCKET type is unsigned.
  7224.  */
  7225. #define INVALID_SOCKET  (SOCKET)(~0)
  7226. #define SOCKET_ERROR            (-1)
  7227.  
  7228. /*
  7229.  * Types
  7230.  */
  7231. #define SOCK_STREAM     1               /* stream socket */
  7232. #define SOCK_DGRAM      2               /* datagram socket */
  7233. #define SOCK_RAW        3               /* raw-protocol interface */
  7234. #define SOCK_RDM        4               /* reliably-delivered message */
  7235. #define SOCK_SEQPACKET  5               /* sequenced packet stream */
  7236.  
  7237. /*
  7238.  * Option flags per-socket.
  7239.  */
  7240. #define SO_DEBUG        0x0001          /* turn on debugging info recording */
  7241. #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
  7242. #define SO_REUSEADDR    0x0004          /* allow local address reuse */
  7243. #define SO_KEEPALIVE    0x0008          /* keep connections alive */
  7244. #define SO_DONTROUTE    0x0010          /* just use interface addresses */
  7245. #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
  7246. #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
  7247. #define SO_LINGER       0x0080          /* linger on close if data present */
  7248. #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
  7249.  
  7250. #define SO_DONTLINGER   (u_int)(~SO_LINGER)
  7251.  
  7252. /*
  7253.  * Additional options.
  7254.  */
  7255. #define SO_SNDBUF       0x1001          /* send buffer size */
  7256. #define SO_RCVBUF       0x1002          /* receive buffer size */
  7257. #define SO_SNDLOWAT     0x1003          /* send low-water mark */
  7258. #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
  7259. #define SO_SNDTIMEO     0x1005          /* send timeout */
  7260. #define SO_RCVTIMEO     0x1006          /* receive timeout */
  7261. #define SO_ERROR        0x1007          /* get error status and clear */
  7262. #define SO_TYPE         0x1008          /* get socket type */
  7263.  
  7264. /*
  7265.  * TCP options.
  7266.  */
  7267. #define TCP_NODELAY     0x0001
  7268.  
  7269. /*
  7270.  * Address families.
  7271.  */
  7272. #define AF_UNSPEC       0               /* unspecified */
  7273. #define AF_UNIX         1               /* local to host (pipes, portals) */
  7274. #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
  7275. #define AF_IMPLINK      3               /* arpanet imp addresses */
  7276. #define AF_PUP          4               /* pup protocols: e.g. BSP */
  7277. #define AF_CHAOS        5               /* mit CHAOS protocols */
  7278. #define AF_NS           6               /* XEROX NS protocols */
  7279. #define AF_ISO          7               /* ISO protocols */
  7280. #define AF_OSI          AF_ISO          /* OSI is ISO */
  7281. #define AF_ECMA         8               /* european computer manufacturers */
  7282. #define AF_DATAKIT      9               /* datakit protocols */
  7283. #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
  7284. #define AF_SNA          11              /* IBM SNA */
  7285. #define AF_DECnet       12              /* DECnet */
  7286. #define AF_DLI          13              /* Direct data link interface */
  7287. #define AF_LAT          14              /* LAT */
  7288. #define AF_HYLINK       15              /* NSC Hyperchannel */
  7289. #define AF_APPLETALK    16              /* AppleTalk */
  7290. #define AF_NETBIOS      17              /* NetBios-style addresses */
  7291.  
  7292. #define AF_MAX          18
  7293.  
  7294. /*
  7295.  * Structure used by kernel to store most
  7296.  * addresses.
  7297.  */
  7298. struct sockaddr {
  7299.         u_short sa_family;              /* address family */
  7300.         char    sa_data[14];            /* up to 14 bytes of direct address */
  7301. };
  7302.  
  7303. /*
  7304.  * Structure used by kernel to pass protocol
  7305.  * information in raw sockets.
  7306.  */
  7307. struct sockproto {
  7308.         u_short sp_family;              /* address family */
  7309.         u_short sp_protocol;            /* protocol */
  7310. };
  7311.  
  7312. /*
  7313.  * Protocol families, same as address families for now.
  7314.  */
  7315. #define PF_UNSPEC       AF_UNSPEC
  7316. #define PF_UNIX         AF_UNIX
  7317. #define PF_INET         AF_INET
  7318. #define PF_IMPLINK      AF_IMPLINK
  7319. #define PF_PUP          AF_PUP
  7320. #define PF_CHAOS        AF_CHAOS
  7321. #define PF_NS           AF_NS
  7322. #define PF_ISO          AF_ISO
  7323. #define PF_OSI          AF_OSI
  7324. #define PF_ECMA         AF_ECMA
  7325. #define PF_DATAKIT      AF_DATAKIT
  7326. #define PF_CCITT        AF_CCITT
  7327. #define PF_SNA          AF_SNA
  7328. #define PF_DECnet       AF_DECnet
  7329. #define PF_DLI          AF_DLI
  7330. #define PF_LAT          AF_LAT
  7331. #define PF_HYLINK       AF_HYLINK
  7332. #define PF_APPLETALK    AF_APPLETALK
  7333.  
  7334. #define PF_MAX          AF_MAX
  7335.  
  7336. /*
  7337.  * Structure used for manipulating linger option.
  7338.  */
  7339. struct  linger {
  7340.         u_short l_onoff;                /* option on/off */
  7341.         u_short l_linger;               /* linger time */
  7342. };
  7343.  
  7344. /*
  7345.  * Level number for (get/set)sockopt() to apply to socket itself.
  7346.  */
  7347. #define SOL_SOCKET      0xffff          /* options for socket level */
  7348.  
  7349. /*
  7350.  * Maximum queue length specifiable by listen.
  7351.  */
  7352. #define SOMAXCONN       5
  7353.  
  7354. #define MSG_OOB         0x1             /* process out-of-band data */
  7355. #define MSG_PEEK        0x2             /* peek at incoming message */
  7356. #define MSG_DONTROUTE   0x4             /* send without using routing tables */
  7357.  
  7358. #define MSG_MAXIOVLEN   16
  7359.  
  7360. /*
  7361.  * Define constant based on rfc883, used by gethostbyxxxx() calls.
  7362.  */
  7363. #define MAXGETHOSTSTRUCT        1024
  7364.  
  7365. /*
  7366.  * Define flags to be used with the WSAAsyncSelect() call.
  7367.  */
  7368. #define FD_READ         0x01
  7369. #define FD_WRITE        0x02
  7370. #define FD_OOB          0x04
  7371. #define FD_ACCEPT       0x08
  7372. #define FD_CONNECT      0x10
  7373. #define FD_CLOSE        0x20
  7374.  
  7375. /*
  7376.  * All Windows Sockets error constants are biased by WSABASEERR from
  7377.  * the "normal"
  7378.  */
  7379. #define WSABASEERR              10000
  7380. /*
  7381.  * Windows Sockets definitions of regular Microsoft C error constants
  7382.  */
  7383. #define WSAEINTR                (WSABASEERR+4)
  7384. #define WSAEBADF                (WSABASEERR+9)
  7385. #define WSAEACCES               (WSABASEERR+13)
  7386. #define WSAEFAULT               (WSABASEERR+14)
  7387. #define WSAEINVAL               (WSABASEERR+22)
  7388. #define WSAEMFILE               (WSABASEERR+24)
  7389.  
  7390. /*
  7391.  * Windows Sockets definitions of regular Berkeley error constants
  7392.  */
  7393. #define WSAEWOULDBLOCK          (WSABASEERR+35)
  7394. #define WSAEINPROGRESS          (WSABASEERR+36)
  7395. #define WSAEALREADY             (WSABASEERR+37)
  7396. #define WSAENOTSOCK             (WSABASEERR+38)
  7397. #define WSAEDESTADDRREQ         (WSABASEERR+39)
  7398. #define WSAEMSGSIZE             (WSABASEERR+40)
  7399. #define WSAEPROTOTYPE           (WSABASEERR+41)
  7400. #define WSAENOPROTOOPT          (WSABASEERR+42)
  7401. #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
  7402. #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
  7403. #define WSAEOPNOTSUPP           (WSABASEERR+45)
  7404. #define WSAEPFNOSUPPORT         (WSABASEERR+46)
  7405. #define WSAEAFNOSUPPORT         (WSABASEERR+47)
  7406. #define WSAEADDRINUSE           (WSABASEERR+48)
  7407. #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
  7408. #define WSAENETDOWN             (WSABASEERR+50)
  7409. #define WSAENETUNREACH          (WSABASEERR+51)
  7410. #define WSAENETRESET            (WSABASEERR+52)
  7411. #define WSAECONNABORTED         (WSABASEERR+53)
  7412. #define WSAECONNRESET           (WSABASEERR+54)
  7413. #define WSAENOBUFS              (WSABASEERR+55)
  7414. #define WSAEISCONN              (WSABASEERR+56)
  7415. #define WSAENOTCONN             (WSABASEERR+57)
  7416. #define WSAESHUTDOWN            (WSABASEERR+58)
  7417. #define WSAETOOMANYREFS         (WSABASEERR+59)
  7418. #define WSAETIMEDOUT            (WSABASEERR+60)
  7419. #define WSAECONNREFUSED         (WSABASEERR+61)
  7420. #define WSAELOOP                (WSABASEERR+62)
  7421. #define WSAENAMETOOLONG         (WSABASEERR+63)
  7422. #define WSAEHOSTDOWN            (WSABASEERR+64)
  7423. #define WSAEHOSTUNREACH         (WSABASEERR+65)
  7424. #define WSAENOTEMPTY            (WSABASEERR+66)
  7425. #define WSAEPROCLIM             (WSABASEERR+67)
  7426. #define WSAEUSERS               (WSABASEERR+68)
  7427. #define WSAEDQUOT               (WSABASEERR+69)
  7428. #define WSAESTALE               (WSABASEERR+70)
  7429. #define WSAEREMOTE              (WSABASEERR+71)
  7430.  
  7431. /*
  7432.  * Extended Windows Sockets error constant definitions
  7433.  */
  7434. #define WSASYSNOTREADY          (WSABASEERR+91)
  7435. #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
  7436. #define WSANOTINITIALISED       (WSABASEERR+93)
  7437.  
  7438. /*
  7439.  * Error return codes from gethostbyname() and gethostbyaddr()
  7440.  * (when using the resolver). Note that these errors are
  7441.  * retrieved via WSAGetLastError() and must therefore follow
  7442.  * the rules for avoiding clashes with error numbers from
  7443.  * specific implementations or language run-time systems.
  7444.  * For this reason the codes are based at WSABASEERR+1001.
  7445.  * Note also that [WSA]NO_ADDRESS is defined only for
  7446.  * compatibility purposes.
  7447.  */
  7448.  
  7449. #define h_errno         WSAGetLastError()
  7450.  
  7451. /* Authoritative Answer: Host not found */
  7452. #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
  7453. #define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
  7454.  
  7455. /* Non-Authoritative: Host not found, or SERVERFAIL */
  7456. #define WSATRY_AGAIN            (WSABASEERR+1002)
  7457. #define TRY_AGAIN               WSATRY_AGAIN
  7458.  
  7459. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  7460. #define WSANO_RECOVERY          (WSABASEERR+1003)
  7461. #define NO_RECOVERY             WSANO_RECOVERY
  7462.  
  7463. /* Valid name, no data record of requested type */
  7464. #define WSANO_DATA              (WSABASEERR+1004)
  7465. #define NO_DATA                 WSANO_DATA
  7466.  
  7467. /* no address, look for MX record */
  7468. #define WSANO_ADDRESS           WSANO_DATA
  7469. #define NO_ADDRESS              WSANO_ADDRESS
  7470.  
  7471. /*
  7472.  * Windows Sockets errors redefined as regular Berkeley error constants
  7473.  */
  7474. #define EWOULDBLOCK             WSAEWOULDBLOCK
  7475. #define EINPROGRESS             WSAEINPROGRESS
  7476. #define EALREADY                WSAEALREADY
  7477. #define ENOTSOCK                WSAENOTSOCK
  7478. #define EDESTADDRREQ            WSAEDESTADDRREQ
  7479. #define EMSGSIZE                WSAEMSGSIZE
  7480. #define EPROTOTYPE              WSAEPROTOTYPE
  7481. #define ENOPROTOOPT             WSAENOPROTOOPT
  7482. #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
  7483. #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
  7484. #define EOPNOTSUPP              WSAEOPNOTSUPP
  7485. #define EPFNOSUPPORT            WSAEPFNOSUPPORT
  7486. #define EAFNOSUPPORT            WSAEAFNOSUPPORT
  7487. #define EADDRINUSE              WSAEADDRINUSE
  7488. #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
  7489. #define ENETDOWN                WSAENETDOWN
  7490. #define ENETUNREACH             WSAENETUNREACH
  7491. #define ENETRESET               WSAENETRESET
  7492. #define ECONNABORTED            WSAECONNABORTED
  7493. #define ECONNRESET              WSAECONNRESET
  7494. #define ENOBUFS                 WSAENOBUFS
  7495. #define EISCONN                 WSAEISCONN
  7496. #define ENOTCONN                WSAENOTCONN
  7497. #define ESHUTDOWN               WSAESHUTDOWN
  7498. #define ETOOMANYREFS            WSAETOOMANYREFS
  7499. #define ETIMEDOUT               WSAETIMEDOUT
  7500. #define ECONNREFUSED            WSAECONNREFUSED
  7501. #define ELOOP                   WSAELOOP
  7502. #define ENAMETOOLONG            WSAENAMETOOLONG
  7503. #define EHOSTDOWN               WSAEHOSTDOWN
  7504. #define EHOSTUNREACH            WSAEHOSTUNREACH
  7505. #define ENOTEMPTY               WSAENOTEMPTY
  7506. #define EPROCLIM                WSAEPROCLIM
  7507. #define EUSERS                  WSAEUSERS
  7508. #define EDQUOT                  WSAEDQUOT
  7509. #define ESTALE                  WSAESTALE
  7510. #define EREMOTE                 WSAEREMOTE
  7511.  
  7512. /* Socket function prototypes */
  7513.  
  7514. #ifdef __cplusplus
  7515. extern "C" {
  7516. #endif
  7517.  
  7518. SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
  7519.                           int FAR *addrlen);
  7520.  
  7521. int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR *addr, int namelen);
  7522.  
  7523. int PASCAL FAR closesocket (SOCKET s);
  7524.  
  7525. int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR *name, int namelen);
  7526.  
  7527. int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp);
  7528.  
  7529. int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
  7530.                             int FAR * namelen);
  7531.  
  7532. int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
  7533.                             int FAR * namelen);
  7534.  
  7535. int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
  7536.                            char FAR * optval, int FAR *optlen);
  7537.  
  7538. u_long PASCAL FAR htonl (u_long hostlong);
  7539.  
  7540. u_short PASCAL FAR htons (u_short hostshort);
  7541.  
  7542. unsigned long PASCAL FAR inet_addr (const char FAR * cp);
  7543.  
  7544. char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
  7545.  
  7546. int PASCAL FAR listen (SOCKET s, int backlog);
  7547.  
  7548. u_long PASCAL FAR ntohl (u_long netlong);
  7549.  
  7550. u_short PASCAL FAR ntohs (u_short netshort);
  7551.  
  7552. int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
  7553.  
  7554. int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
  7555.                          struct sockaddr FAR *from, int FAR * fromlen);
  7556.  
  7557. int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
  7558.                        fd_set FAR *exceptfds, const struct timeval FAR *timeout);
  7559.  
  7560. int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
  7561.  
  7562. int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
  7563.                        const struct sockaddr FAR *to, int tolen);
  7564.  
  7565. int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
  7566.                            const char FAR * optval, int optlen);
  7567.  
  7568. int PASCAL FAR shutdown (SOCKET s, int how);
  7569.  
  7570. SOCKET PASCAL FAR socket (int af, int type, int protocol);
  7571.  
  7572. /* Database function prototypes */
  7573.  
  7574. struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
  7575.                                               int len, int type);
  7576.  
  7577. struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
  7578.  
  7579. int PASCAL FAR gethostname (char FAR * name, int namelen);
  7580.  
  7581. struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
  7582.  
  7583. struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
  7584.                                               const char FAR * proto);
  7585.  
  7586. struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
  7587.  
  7588. struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
  7589.  
  7590. /* Microsoft Windows Extension function prototypes */
  7591.  
  7592. int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
  7593.  
  7594. int PASCAL FAR WSACleanup(void);
  7595.  
  7596. void PASCAL FAR WSASetLastError(int iError);
  7597.  
  7598. int PASCAL FAR WSAGetLastError(void);
  7599.  
  7600. BOOL PASCAL FAR WSAIsBlocking(void);
  7601.  
  7602. int PASCAL FAR WSAUnhookBlockingHook(void);
  7603.  
  7604. FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
  7605.  
  7606. int PASCAL FAR WSACancelBlockingCall(void);
  7607.  
  7608. HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  7609.                                         const char FAR * name, 
  7610.                                         const char FAR * proto,
  7611.                                         char FAR * buf, int buflen);
  7612.  
  7613. HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  7614.                                         const char FAR * proto, char FAR * buf,
  7615.                                         int buflen);
  7616.  
  7617. HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  7618.                                          const char FAR * name, char FAR * buf,
  7619.                                          int buflen);
  7620.  
  7621. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  7622.                                            int number, char FAR * buf,
  7623.                                            int buflen);
  7624.  
  7625. HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  7626.                                         const char FAR * name, char FAR * buf,
  7627.                                         int buflen);
  7628.  
  7629. HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  7630.                                         const char FAR * addr, int len, int type,
  7631.                                         const char FAR * buf, int buflen);
  7632.  
  7633. int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  7634.  
  7635. int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  7636.                                long lEvent);
  7637.  
  7638. #ifdef __cplusplus
  7639. }
  7640. #endif
  7641.  
  7642. /* Microsoft Windows Extended data types */
  7643. typedef struct sockaddr SOCKADDR;
  7644. typedef struct sockaddr *PSOCKADDR;
  7645. typedef struct sockaddr FAR *LPSOCKADDR;
  7646.  
  7647. typedef struct sockaddr_in SOCKADDR_IN;
  7648. typedef struct sockaddr_in *PSOCKADDR_IN;
  7649. typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
  7650.  
  7651. typedef struct linger LINGER;
  7652. typedef struct linger *PLINGER;
  7653. typedef struct linger FAR *LPLINGER;
  7654.  
  7655. typedef struct in_addr IN_ADDR;
  7656. typedef struct in_addr *PIN_ADDR;
  7657. typedef struct in_addr FAR *LPIN_ADDR;
  7658.  
  7659. typedef struct fd_set FD_SET;
  7660. typedef struct fd_set *PFD_SET;
  7661. typedef struct fd_set FAR *LPFD_SET;
  7662.  
  7663. typedef struct hostent HOSTENT;
  7664. typedef struct hostent *PHOSTENT;
  7665. typedef struct hostent FAR *LPHOSTENT;
  7666.  
  7667. typedef struct servent SERVENT;
  7668. typedef struct servent *PSERVENT;
  7669. typedef struct servent FAR *LPSERVENT;
  7670.  
  7671. typedef struct protoent PROTOENT;
  7672. typedef struct protoent *PPROTOENT;
  7673. typedef struct protoent FAR *LPPROTOENT;
  7674.  
  7675. typedef struct timeval TIMEVAL;
  7676. typedef struct timeval *PTIMEVAL;
  7677. typedef struct timeval FAR *LPTIMEVAL;
  7678.  
  7679. /*
  7680.  * Windows message parameter composition and decomposition
  7681.  * macros.
  7682.  *
  7683.  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  7684.  * when constructing the response to a WSAAsyncGetXByY() routine.
  7685.  */
  7686. #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
  7687. /*
  7688.  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  7689.  * when constructing the response to WSAAsyncSelect().
  7690.  */
  7691. #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
  7692. /*
  7693.  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  7694.  * to extract the buffer length from the lParam in the response
  7695.  * to a WSAGetXByY().
  7696.  */
  7697. #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  7698. /*
  7699.  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  7700.  * to extract the error code from the lParam in the response
  7701.  * to a WSAGetXByY().
  7702.  */
  7703. #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  7704. /*
  7705.  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  7706.  * to extract the event code from the lParam in the response
  7707.  * to a WSAAsyncSelect().
  7708.  */
  7709. #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
  7710. /*
  7711.  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  7712.  * to extract the error code from the lParam in the response
  7713.  * to a WSAAsyncSelect().
  7714.  */
  7715. #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
  7716.  
  7717. #endif  /* _WINSOCKAPI_ */
  7718.  
  7719.  
  7720.                    Appendix B: Notes for Windows Sockets Suppliers 149
  7721.  
  7722.  
  7723. Appendix B.  Notes for Windows Sockets Suppliers
  7724.  
  7725. B.1 Introduction
  7726. A Windows Sockets implementation must implement ALL the functionality
  7727. described in the Windows Sockets documentation.  Validation of
  7728. compliance is discussed in section B.8.
  7729.  
  7730. Windows Sockets Version 1.1 implementations must support both TCP and
  7731. UDP type sockets.  An implementation may support raw sockets (of type
  7732. SOCK_RAW), but their use is deprecated.
  7733.  
  7734. Certain APIs documented above have special notes for Windows Sockets
  7735. implementors.  A Windows Sockets implementation should pay special
  7736. attention to conforming to the API as documented.  The Special Notes
  7737. are provided for assistance and clarification.
  7738.  
  7739.  
  7740. B.2 Windows Sockets Components
  7741. B.2.1 Development Components
  7742. The Windows Sockets development components for use by Windows Sockets
  7743. application developers will be provided by each Windows Sockets
  7744. supplier.  These Windows Sockets development components are:
  7745.  
  7746. Component           Description
  7747. Windows Sockets Documentation This document
  7748. WINSOCK.LIB file    Windows Sockets API Import Library
  7749. WINSOCK.H file      Windows Sockets Header File
  7750. NETDB.H file        Berkeley Compatible Header File
  7751. ARPA/INET.H file    Berkeley Compatible Header File
  7752. SYS/TIME.H file     Berkeley Compatible Header File
  7753. SYS/SOCKET.H file   Berkeley Compatible Header File
  7754. NETINET/IN.H file   Berkeley Compatible Header File
  7755.  
  7756. B.2.2 Run Time Components
  7757. The run time component provided by each Windows Sockets supplier is:
  7758.  
  7759. Component           Description
  7760. WINSOCK.DLL         The Windows Sockets API implementation DLL
  7761.  
  7762.  
  7763. B.3 Multithreadedness and blocking routines.
  7764. Data areas returned by, for example, the getXbyY() routines MUST be on
  7765. a per thread basis.
  7766.  
  7767. Note that an application MUST be prevented from making multiple nested
  7768. Windows Sockets function calls.  Only one outstanding function call
  7769. will be allowed for a particular task.  Any Windows Sockets call
  7770. performed when an existing blocking call is already outstanding will
  7771. fail with an error code of WSAEINPROGRESS.  There are two exceptions
  7772. to this restriction: WSACancelBlockingCall() and WSAIsBlocking() may
  7773. be called at any time.  Windows Sockets suppliers should note that
  7774. although preliminary drafts of this specification indicated that the
  7775. restriction only applied to blocking function calls, and that it would
  7776. be permissible to make non-blocking calls while a blocking call was in
  7777. progress, this is no longer true.
  7778.  
  7779.  
  7780.  
  7781. 150 Appendix B: Notes for Windows Sockets Suppliers
  7782.  
  7783. Regarding the implementation of blocking routines, the solution in
  7784. Windows Sockets is to simulate the blocking mechanism by having each
  7785. routine call PeekMessage() as it waits for the completion of its
  7786. operation.  In anticipation of this, the function WSASetBlockingHook()
  7787. is provided to allow the programmer to define a special routine to be
  7788. called instead of the default PeekMessage() loop.  The blocking hook
  7789. functions are discussed in more detail in 4.3.13,
  7790. WSASetBlockingHook().
  7791.  
  7792.  
  7793. B.4 Database Files
  7794. The database routines in the getXbyY() family (gethostbyaddr(), etc.)
  7795. were originally designed (in the first Berkeley UNIX releases) as
  7796. mechanisms for looking up information in text databases.  A Windows
  7797. Sockets supplier may choose to employ local files OR a name service to
  7798. provide some or all of this information.  If local files exist, the
  7799. format of the files must be identical to that used in BSD UNIX,
  7800. allowing for the differences in text file formats.
  7801.  
  7802.  
  7803. B.5 FD_ISSET
  7804. It is necessary to implement the FD_ISSET Berkeley macro using a
  7805. supporting function: __WSAFDIsSet().  It is the responsibility of a
  7806. Windows Sockets implementation to make this available as part of the
  7807. Windows Sockets API.  Unlike the other functions exported by a Windows
  7808. Sockets DLL, however, this function is not intended to be invoked
  7809. directly by Windows Sockets applications: it should be used only to
  7810. support the FD_ISSET macro.  The source code for this function is
  7811. listed below:
  7812.  
  7813. int FAR
  7814. __WSAFDIsSet(SOCKET fd, fd_set FAR *set)
  7815. {
  7816.     int i = set->fd_count;
  7817.  
  7818.     while (i--)
  7819.      if (set->fd_array[i] == fd)
  7820.          return 1;
  7821.  
  7822.     return 0;
  7823. }
  7824.  
  7825.  
  7826. B.6 Error Codes
  7827. In order to avoid conflict between various compiler environments
  7828. Windows Sockets implementations MUST return the error codes listed in
  7829. the API specification, using the manifest constants beginning with
  7830. "WSA".  The Berkeley-compatible error code definitions are provided
  7831. solely for compatibility purposes for applications which are being
  7832. ported from other platforms.
  7833.  
  7834.  
  7835. B.7 DLL Ordinal Numbers
  7836. The winsock.def file for use by every Windows Sockets implementation
  7837. is as follows.  Ordinal values starting at 1000 are reserved for
  7838. Windows Sockets implementors to use for exporting private interfaces
  7839. to their DLLs.  A Windows Sockets implementation must not use any
  7840.  
  7841.  
  7842.  
  7843.                    Appendix B: Notes for Windows Sockets Suppliers 151
  7844.  
  7845. ordinals 999 and below except for those APIs listed below.  An
  7846. application which wishes to work with any Windows Sockets DLL must use
  7847. only those routines listed below; using a private export makes an
  7848. application dependent on a particular Windows Sockets implementation.
  7849.  
  7850. ;
  7851. ;         File: winsock.def
  7852. ;       System: MS-Windows 3.x
  7853. ;      Summary: Module definition file for Windows Sockets DLL.
  7854. ;
  7855.  
  7856. LIBRARY         WINSOCK         ; Application's module name
  7857.  
  7858. DESCRIPTION     'BSD Socket API for Windows'
  7859.  
  7860. EXETYPE         WINDOWS         ; required for all windows
  7861. applications
  7862.  
  7863. STUB            'WINSTUB.EXE'   ; generates error message if
  7864. application
  7865.                                 ; is run without Windows
  7866.  
  7867. ;CODE can be FIXED in memory because of potential upcalls
  7868. CODE            PRELOAD         FIXED
  7869.  
  7870. ;DATA must be SINGLE and at a FIXED location since this is a DLL
  7871. DATA            PRELOAD         FIXED           SINGLE
  7872.  
  7873. HEAPSIZE        1024
  7874. STACKSIZE       16384
  7875.  
  7876. ; All functions that will be called by any Windows routine
  7877. ; must be exported.  Any additional exports beyond those defined
  7878. ; here must have ordinal numbers 1000 or above.
  7879.  
  7880. EXPORTS
  7881.         accept                         @1
  7882.         bind                           @2
  7883.         closesocket                    @3
  7884.         connect                        @4
  7885.         getpeername                    @5
  7886.         getsockname                    @6
  7887.         getsockopt                     @7
  7888.         htonl                          @8
  7889.         htons                          @9
  7890.         inet_addr                      @10
  7891.         inet_ntoa                      @11
  7892.         ioctlsocket                    @12
  7893.         listen                         @13
  7894.         ntohl                          @14
  7895.         ntohs                          @15
  7896.         recv                           @16
  7897.         recvfrom                       @17
  7898.         select                         @18
  7899.         send                           @19
  7900.         sendto                         @20
  7901.         setsockopt                     @21
  7902.  
  7903.  
  7904.  
  7905. 152 Appendix B: Notes for Windows Sockets Suppliers
  7906.  
  7907.         shutdown                       @22
  7908.         socket                         @23
  7909.  
  7910.         gethostbyaddr                  @51
  7911.         gethostbyname                  @52
  7912.         getprotobyname                 @53
  7913.         getprotobynumber               @54
  7914.         getservbyname                  @55
  7915.         getservbyport                  @56
  7916.         gethostname                    @57
  7917.  
  7918.         WSAAsyncSelect                 @101
  7919.         WSAAsyncGetHostByAddr          @102
  7920.         WSAAsyncGetHostByName          @103
  7921.         WSAAsyncGetProtoByNumber       @104
  7922.         WSAAsyncGetProtoByName         @105
  7923.         WSAAsyncGetServByPort          @106
  7924.         WSAAsyncGetServByName          @107
  7925.         WSACancelAsyncRequest          @108
  7926.         WSASetBlockingHook             @109
  7927.         WSAUnhookBlockingHook          @110
  7928.         WSAGetLastError                @111
  7929.         WSASetLastError                @112
  7930.         WSACancelBlockingCall          @113
  7931.         WSAIsBlocking                  @114
  7932.         WSAStartup                     @115
  7933.         WSACleanup                     @116
  7934.  
  7935.         __WSAFDIsSet                   @151
  7936.  
  7937.         WEP                            @500    RESIDENTNAME
  7938.  
  7939. ;eof
  7940.  
  7941.  
  7942. B.8 Validation Suite
  7943.  
  7944. An alpha version of the Windows Sockets Test and Validation Suite to
  7945. ensure Windows Sockets compatibility will be available at Fall 1992
  7946. Interop from Microsoft.  This alpha version includes functionality
  7947. testing of the Windows Sockets interface and is supported by a
  7948. comprehensive scripting language.  The final version of the suite is
  7949. expected to be available in January 1993, and it will include a more
  7950. sophisticated user interface.  Beta versions may be available in the
  7951. interim.  Further documentation on the test suite is available from
  7952. Microsoft.
  7953.  
  7954.  
  7955.  
  7956.                    Appendix B: Notes for Windows Sockets Suppliers 153
  7957.  
  7958.  
  7959. Appendix C.  For Further Reference
  7960.  
  7961. This specification is intended to cover the Windows Sockets interface
  7962. to TCP/IP in detail.  Many details of TCP/IP and Windows, however, are
  7963. intentionally omitted in the interest of brevity, and this
  7964. specification often assumes background knowledge of these topics.  For
  7965. more information, the following references may be helpful:
  7966.  
  7967. Braden, R.[1989], RFC 1122, Requirements for Internet Hosts--
  7968.           Communication Layers, Internet Engineering Task Force.
  7969.  
  7970. Comer, D. [1991], Internetworking with TCP/IP Volume I: Principles,
  7971.           Protocols, and Architecture, Prentice Hall, Englewood
  7972.           Cliffs, New Jersey.
  7973.  
  7974. Comer, D. and Stevens, D. [1991], Internetworking with TCP/IP Volume
  7975.           II: Design, Implementation, and Internals, Prentice Hall,
  7976.           Englewood Cliffs, New Jersey.
  7977.  
  7978. Comer, D. and Stevens, D. [1991], Internetworking with TCP/IP Volume
  7979.           III: Client-Server Programming and Applications, Prentice
  7980.           Hall, Englewood Cliffs, New Jersey.
  7981.  
  7982. Leffler, S. et al., An Advanced 4.3BSD Interprocess Communication
  7983.           Tutorial.
  7984.  
  7985. Petzold, C. [1992], Programming Windows 3.1, Microsoft Press, Redmond,
  7986.           Washington.
  7987.  
  7988. Stevens, W.R. [1990], Unix Network Programming, Prentice Hall,
  7989.           Englewood Cliffs, New Jersey.
  7990.  
  7991.  
  7992.  
  7993. Appendix D.  Background Information
  7994.  
  7995. D.1 Legal Status of Windows Sockets
  7996.  
  7997. The copyright for the Windows Sockets specification is owned by the
  7998. specification authors listed on the title page.  Permission is granted
  7999. to redistribute this specification in any form, provided that the
  8000. contents of the specification are not modified.  Windows Sockets
  8001. implementors are encouraged to include this specification with their
  8002. product documentation.
  8003.  
  8004. The Windows Sockets logo on the title page of this document is meant
  8005. for use on both Windows Sockets implementations and for applications
  8006. that use the Windows Sockets interface.  Use of the logo is encouraged
  8007. on packaging, documentation, collateral, and advertising.  The logo is
  8008. available on microdyne.com in pub/winsock as winsock.bmp.  The
  8009. suggested color for the logo's title bar is blue, the electrical
  8010. socket grey, and the text and outline black.
  8011.  
  8012.  
  8013.  
  8014. D.2 The Story Behind the Windows Sockets Icon
  8015.  
  8016.  
  8017.  
  8018. 154 Appendix B: Notes for Windows Sockets Suppliers
  8019.  
  8020.  
  8021. (by Alistair Banks, Microsoft Corporation)
  8022.  
  8023. We thought we'd do a "Wind Sock" at one stage--but you try to get that
  8024. into 32x32 bits! It would have had to look wavy and colorful, and...
  8025. well, it just didn't work. Also, our graphics designers have
  8026. "opinions"
  8027. about the icons truly representing what they are--people would have
  8028. thought this was "The colorful wavy tube specification 1.0!"
  8029.  
  8030. I tried to explain "API" "Programming Interface" to the artist--we
  8031. ended up with toolbox icons with little flying windows
  8032.  
  8033. Then we came to realise that we should be going after the shortened
  8034. form of the name, rather the name in full... Windows Sockets... And so
  8035. we went for that - so she drew (now remember I'm English and you're
  8036. probably American) "Windows Spanner", a.k.a. a socket wrench.  In the
  8037. U.S. you'd have been talking about the "Windows Socket spec" OK, but
  8038. in England that would have been translated as "Windows Spanner Spec
  8039. 1.0" - so we went to Electrical sockets - well the first ones came out
  8040. looking like "Windows Pignose Spec 1.0"!!!!
  8041.  
  8042. So how do you use 32x32, get an international electrical socket! You
  8043. take the square type (American & English OK, Europe & Australia are
  8044. too rounded)--you choose the American one, because it's on the wall in
  8045. front of you (and it's more compact (but less safe, IMHO) and then you
  8046. turn it upside down, thereby compromising its nationality!
  8047.  
  8048. [IMHO = "In My Humble Opinion"--ed.]
  8049.  
  8050.